Using the database to hold application settings
I am looking at ways to make our application more extensible and easier to manipulate without having to alter the web.config (or, in our case, application.config files, which contain the appsettings node). One way I have thought about is keeping the app settings in the database table that has a sqlcachedependancy. This means that: Any time a setting is changed in the database, the cache is invalidated, and the settings are retrieved again, thus updating the application in realtime without having to alter files and restart the entire app. We can create a custom tool which allows us to alter the settings. The cons as I see it are that this may cause serious logic problems in that, if you have something that checks an appsetting at the start of a process, and it then changes halfway through, you could end up unintentionally altering the process flow, as the requirement for a complete application restart is negated. Is there a way round this? Is there a better way to manage appsettings, so that you can alter them on the fly remotely for one, several, or all servers in one go?
I think you've nailed the two major players: either you have access to the file system and you put all your settings in a plethora of *.config files there OR: you don't have access (or only very limited access) to the server's file system and thus you're probably better off putting config settings and user preferences in a database, basically leaving nothing but the connection string to the config file on disk Both approaches have their pros and cons. I've been trying for a long time to find a way to "materialize" a config section from a database field, so that I could basically just use the config XML, but stored in a database field. Unfortunately, the entire .NET 2.0 config system is very much "locked down" and just only assumes data will come from files - there's no way to plug in e.g. a database provider to allow the config system to read its contents from a database field :-( Really too bad! The only other approach I've seen is a "ConfigurationService" in the StockTrader 2.0 sample app provided by Microsoft, but for my needs, it felt like overkill and like a really complex, really heavy-weight subsystem.
You could use SQLite, which will be a self-contained DB in a single file. Two birds with one stone?
If you reference an external config file that contains appsettings (leaving everything else in the normal app.config) then I believe editing it only reloads those settings, it doesn't force the whole app to restart. There's a similar question on the subject here: Nested app.config (web.config) files WRT the problem of values changing in the middle of program execution, I guess you could locally cache the values, and raise an event when they change, allowing routines to reach a suitable point before using the updated values. I think in asp.net we sort of get this for free because each page lifecyle is distinct, so the value is simply applied to new page requests only, not in the middle of an execution. Edit: A little extra info: Configuration Changes Cause a Restart of the Application Domain From MSDN: Changes to configuration settings in Web.config files indirectly cause the application domain to restart. This behavior occurs by design. You can optionally use the configSource attribute to reference external configuration files that do not cause a restart when a change is made. For more information, see configSource in General Attributes Inherited by Section Elements. More information on the ConfigurationManager class in the System.Configuration namespace which could be used to modify the config files programatically (ie in a custom tool, if relevant disk read permissions can be provided). If you stick to using the built in configuration classes, I think changing the external configs, would not cause application restart, but would raise events (such as property changed) which you could handle, to ensure your code is not caught out by changing settings.
convert datetime format from csv to mysql database
create json array in c#
VBA to C# with statement [duplicate]
How can I make a user control move in runtime In wpf c#
How to convert session to int, when using sql
C# Sign Assembly Using Code
Getting the time part of a DateTime and feeding it to a Masked Text box
Is it possible to scrape contents of a GridView control in another .NET application?
Send Object as parameter to Dll function
wp8 Application object
advice for SQL query with row values as columns
CRM 2011 Custom Workflow accessing data from a created record trigger
Numeric Like Condition - Zero or More Leading Zeros
C# - Return variable from child window to parent window in WPF
Testing for two conditions in one IF statement
Missing References on C# Program System.XML.Contracts