How to save connection string

Topics: Data Access Application Block, Enterprise Library Core
Aug 5 at 6:32 PM
Edited Aug 5 at 7:10 PM
Is it possible for me to use Enterprise library so when i create a DAL (Data Access Layer) in a class project (which uses Linq to SQL dbml file) and a separate user end project (i.e. ASP .Net Website) it would pick up the connection string from the Web.Config without having the recompile my DAL (when switching between Test and Production environments)?

If so any examples on this or what section i need to read up on?

Thanks
Editor
Aug 11 at 3:31 AM
The default behavior is for Enterprise Library to read configuration from the web.config (or app.config). It will look up the connection string by name. If you are using Enterprise Library 6 just make sure that bootstrap the blocks before referencing or using a Database:
var configSource = ConfigurationSourceFactory.Create();
DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(configSource), false);

If you want to use your own configuration file for the DAL then you could use a FileConfigurationSource to load the DAL's configuration file and pass that in toe the DatabaseProviderFactory.

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to
Aug 26 at 3:56 PM
Thanks - im a little lost so i will explain how i do things in case ive missed a step. Sorry im new with EL6 and have been reading relevant docs but trying to plug in new capabilities so i could well be doing something incorrectly.
  1. Create my DAL > Add a dbml file. As soon as i connect to a database it sets the connection. I dont do anything else. Build this application.
  2. Add a web project and set the connection string.
As you can tell i dont add any code from EL6 in my DAL so should i be doing something different in step 1 to insert the code you posted? Or should i need to create a new class and inherit some other class in order for this to work?

Thanks again
Editor
Aug 27 at 3:29 AM
If you are using LINQ To SQL as your DAL then you would have no need to use Enterprise Library Data Access Application Block. The Data Access Application Block is a wrapper over ADO.NET so you are using ADO.NET (or thinking of using ADO.NET) then Enterprise Library could be used in it's place to simplify development (e.g. connection management, parameter derivation, property mapping).

~~
Randy Levy
entlib.support@live.com
Enterprise Library support engineer
Support How-to