I'm currently using the Enterprise Block Cache library and I am trying to change the way it's initialized. By default it will rely on the presence of an exe.config file, but all our config items are stored in a database and I would like to keep it that way. Is there a way to initialize System.Configuration stuff without the use of a local file I had a look at the Cache code and I don't seem to be able to change the initialization process without a lot of work/pain.

Hope my question is clear enough....


Re: .NET Framework Data Access and Storage System.Configuration / loading config from a database

Robert Rossney

I am ignorant of the Enterprise Block Cache library, so take this answer with a grain of salt.

The System.Configuration classes exist entirely to mediate the retrieval (and, in some cases, updating) of configuration settings from application configuration and user setting files. If you want to retrieve configuration information from the database, probably the best way to go about it is to make your own static settings class, populate it from the database, and use its properties instead of the designer-generated Properties.Settings class.

I don't know how hard it is to refactor the Cache code to fix this, but it could just be a matter of search/replace to replace with

If the Cache code is using the System.Configuration classes more extensively, another approach would be to write wrapper classes for each class that Cache is using, e.g. MyNamespace.ConfigurationManager, and then replace the using System.Configuration declaration with using MyNamespace.

Here's what you probably don't want to do: You probably don't want to be getting configuration information out of your database and writing it to the application configuration file so that it's there when the System.Configuration classes try to read it. While this can be made to work, it creates a raft of issues that you'd really rather not have to deal with.

Re: .NET Framework Data Access and Storage System.Configuration / loading config from a database


Hi Robert,

Thanks for your response. It gave me some good ideas to work around the problem. There's in the Enterprise library the notion of Configuration Source (represented by the IConfigurationSource interface). This interface returns ConfigurationSection objects but as it is abstracted from the ConfigurationManager I have managed to create my own source so that I can load my own sections created from the database lookup.

Thanks again!