Writing Configuration to DAAB

Topics: Data Access Application Block
Jun 10, 2007 at 9:33 PM

can someone point me to a clean way to add the configuration info for a new DB from code? in fact, i need to read one and write a similar entry. sorry for the elementary question, i'm paging through the examples and my searches are getting flooded with hits from using the config app, which is not what i need.

Jun 11, 2007 at 5:57 AM
The database information is stored using the standard .NET ConnectionStrings settings. You should be able to access it via ConfigurationManager.ConnectionStrings without too much trouble. There's an Add method there to add a new one.

Or do you need to do something else?

Jun 11, 2007 at 3:01 PM
There are two classes you can use to read database configuration settings other than the obvious ConnectionStrings:


DatabaseSettings settings = DatabaseSettings.GetDatabaseSettings(new SystemConfigurationSource());


DatabaseConfigurationView view = new DatabaseConfigurationView(new SystemConfigurationSource());

I talk about these more in a couple of tutorials:

Reading Connection Strings in Web.Config and App.Config and Enterprise Library DAAB Settings

DatabaseConfigurationView Class in Enterprise Library Data Access Application Block - Read Database Connection Strings and Configuration

The DatabaseConfigurationView is a read-only type of class, but you can probably serialize the DatabaseSettings Class to the configuration file. I haven't done it, but I believe this is how it works internally in the configuration tool.




David Hayden
Microsoft MVP C#
Jun 12, 2007 at 7:44 AM

Thanks - I've been heads down too long! As it turns out, our project needs to create/detach databases on the fly and we're using EntLibs for many things, so until we have time to map the strings into our master db (instead of a file), I simply wanted a quick way to add/remove entries from the file. I hadn't known the 2.0 Configuration space added so much...

Overall, we're seeing a slight gap where we need to pause until the file watcher of EntLib picks up the config file write - is this normal? Going to a DB config provider should alleviate this, yes? BTW,Where's the best example of such a provider?