Cache and SQLConfigurationSource

Topics: Enterprise Library Core
Oct 6, 2009 at 4:48 AM

Hi!

I’m studding the EntLib 4.1 configuration mechanism, particularly interested by the SQLConfigurationSource quick start implementation.

I wonder if anyone can explain how the caching works for the SQLConfigurationSource because every time I get a configuration section, it read it again from the data base.

In the FileConfigurationSourceImplementation of the core (entlib common),  the configuration is kept in a “cachedConfiguration” variable. FileConfigurationSourceImplementation just read the configuration file if the  cachedConfiguration is null.

I was expecting something similar in the SQL implementation. Any sample how to use the SQLConfigurationSource properly?

Thanks!

Oct 6, 2009 at 9:32 AM

Hi,

My understanding of SqlConfigurationSource is, its like the FileConfigurationSource which uses an external config files, the difference is that the SqlConfigurationSource saves your configSections in the Database. On how to use the SqlConfigurationSource, please see this thread http://entlib.codeplex.com/Thread/View.aspx?ThreadId=17125 .

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 6, 2009 at 4:43 PM
Edited Oct 7, 2009 at 3:37 AM

Thanks!

So, in this thread, Mert wrote “4. Add you own stuff, Logging, Caching etc...”. Is talking about the caching application bloc configuration section. This thread is not really what I’m looking for.

My understanding from the source code, is that the SQLConfigurationSource does not cache the ConfigSection. It implements the Source Watcher, seams to attach the watcher to the configuration section, but it doesn’t update the section or a cache when detecting the change in the database.  The GetSection always seams to read the configuration from the database.

Rick

Oct 8, 2009 at 5:43 AM

I verified in the source code and yes, the GetSection implementation of the SqlConfigurationSource always retrieves configuration information from the database.  If you're asking why, we cannot answer design decisions but we'll direct your question to the entlib team.

 

Sarah Urmeneta
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Oct 8, 2009 at 11:47 AM

As far as I know, GetSection makes requests in every fifteen seconds to see if there are any changes.

Consider this scenario;

I have a web.config on live server, and another one on my desktop. They are exactly the same files, but the configuration (of the application blocks) is read and written to database. So if I open the web.config on my desktop and modify it with Enterprise Library Configuration Tool and save it, the changes will be written to database.

I like this idea; "Keeping the configuration information on the database". But if you ask it to any experienced architect or developer, they wouldn't recommend it. Because of performance, relying on network etc..

I actually modified SQLConfigurationSource for my own needs and added, multi computer support (which is also a highly debatable configuration design). On the scenario above, I had web config on my desktop, and six seperate running machines with same config pointed to same database. So when I modify the config on my desktop, the database is updated then each machine updates its own configuration without any restart. I used this design for quite a while and I had no problem!

If I wanted the maximum performance, I wouldn't use Enterprise Library anywhere.
If I wanted good design and code maintainability, I would use it everywhere (unless everyone in the team, should be familiar with it).

Oct 9, 2009 at 2:58 AM

I have no choice. I need to keep the configuration in the database.

I' will try to implement a cache in the SqlConfigurationSourceImplementation class.

I don't really like the SourceWatcher for a database implementation and especially for a web site application.

But I like the ConfigurationChangingEvent functionnality. It may be useful in may application.

I'll try to improve the "Quick Start" for my purpose.

Thank you all!

Rick

 

Nov 4, 2009 at 4:46 PM

rickbussi: If you don't mind I would be interested in the updated "quick start" version you're working on.

I also work with the SqlConfigurationSource and was able to store my settings in the database. Now I want to modify (for example) the logging settings in my application code.

I was able to load the settings and modified them, but what is now the correct way to save the settings back to the database?

The following was not sufficient (I guess only the SqlConfigurationSource settings get saved to the *.config file):

Configuration entlibconfig =  ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
// modify settings..
entlibconfig.Save();

So I found out that calling directly the Save() method of the SqlConfigurationSource instance works:

// get the SqlConfigurationSourceElement instance
SqlConfigurationSource sqlConfigurationSource =  sqlConfigSourceElement.CreateSource() as SqlConfigurationSource;
sqlConfigurationSource.Save(
                sqlConfigSourceElement.ConnectionString, 
                sqlConfigSourceElement.SetStoredProcedure,
                LoggingSettings.SectionName,
                loggingSettings);

But is this the correct way to store the settings back to the database?

Thanks a lot

f0x