Good morning Stephane. Welcome to Microsoft Newsgroup Support Service! My
name is Jialiang Ge [MSFT]. It's my pleasure to work with you on this issue.
I understand you concerns are: how to store&return the configuration
settings of applications without the need to restart the app pool in IIS or
windows service. As you said, neither hard-coded parameters in static
members nor the built-in configuration files (e.g. web.config) meets the
requirement because their updates need the restart of some services. We are
also concerned about the overhead of SQL server if the configurations are
stored in a DB table. Are there any other better choices?
I have three solutions for your references:
1. SQL Server + SQL Dependency Cache
2. txt or xml based setting file + file change callback
3. Windows Registry
---------------1. SQL Server + SQL Dependency Cache-----------
SqlDependency is a feature introduced by .NET 2.0. It can be used in web
applications (SqlCacheDependency) or windows applications (SqlDependency).
SQL Dependency cache stays between your business logic (the retrieval of
configurations) and SQL Server DB (2000 or 2005). The strength of SQL
Dependency is that, when the data in DB is updated, the dependency will be
notified about the change, clear the cache, and force the next retrieval of
the data to query DB. But if the data in DB is not updated, the thousands
of calls of configuration retrieval will not query DB, instead, it gets the
value directly from "cache" in the application's memory. I believe this can
solve your concern of the overhead of SQL server.
SqlDependency is briefly introduced in the MSDN:
http://msdn.microsoft.com/en-us/library/9dz445ks(VS.80).aspx
There are many other materials about it online. If you like this idea,
please tell me you SQL server version (2000 or 2005? SqlDependency is
optimized for SQL server 2005), I will give more samples and documents for
your references.
As a summary of this solution:
STRENGTH:
Good performance, good maintainability, and easy to implement.
WEAKNESS:
If your application itself does not reply on SQL server, SQL server may
look too fat solely for the storage of configuration settings.
-----2. txt or xml based setting file + file change callback ----
Instead of putting the configurations in a .net config file that requires
restart after the update, you may consider storing the values in a txt or
xml files. Our application can read/set the values with .net XML-related
classes. In order to improve the performance for thousands of queries, we
can rely on .net cache + file change callback. File change callbacks are
provided by the .NET class: FileSystemWatcher. It listens to the file
system change notification and raises events when a directory, or file in a
directory, changes.
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
I once wrote a small "setting" class based on FileSystemWatcher for txt
setting files at my spare time. (see the attachment with OE or windows
mail) Its code is just for your references.
As a summary of this solution:
STRENGTH:
Only reply on "local file system", thus, it's not as "fat" as SQL server.
Good maintainability, and easy to implement.
WEAKNESS:
If this solution is going to be used in web application, we may need to do
something to prevent the file from being opened directly by the clients.
You can place xml/txt data files, which cannot be requested directly via
http requests to your server, in the app_data directory.
In addition, the file access permission need to be granted to ASP.NET
application (NETWORK_SERVICE).
http://www.codeproject.com/KB/aspnet/Ahmed_Kader.aspx
---------------------3. Windows Registry ---------------------
I recommend this only for windows service or windows form applications. As
far as I know, a lot of such applications put their configurations in the
registry path:
HKLM/Software/[Company Name]/[Application Name],
There might be other better solutions other than the above three. I will do
more researches. Stephane, please let me know if you have any other
concerns, or need anything else. I will do my best to help you reach a
comfortable resolution.
Regards,
Jialiang Ge (
[email protected], remove 'online.')
Microsoft Online Community Support
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.