c#


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.

Related Links

Microsoft Graph. DriveItem Id format?
DateTime parsing - unexpected result
Measuring mb sent per second with C# sockets? (Multithread)
C# inheritance multiple for different children
IList to JSON fails
Convert to Nested JSON C#
Sending List<Object> WCF POST
Export to excel is exporting check box to excel instead of string
Loop iteration of an array string
Impersonate a user using the Session ID
Is it safe to store and update list in asp.net session via static methods?
Change of the edited cell in a datagridview cell
Trying a REST POST call in C# - using Postman code
List object initialization [duplicate]
How to access HttpContext.Current.User custom attributes in the view
Non-nullable property exception when inserting a new entity

Categories

HOME
macros
domain-driven-design
xamarin.forms
opencv4android
lithium
ubuntu-14.04
localhost
yuv
install
wavefront
samsung-gear-s2
dcos
ethereum
drush
openstack-horizon
bookmarklet
google-street-view
webgl-earth
datazen-server
combinations
tcpdf
datanucleus
formtastic
mex
csproj
javapns
arp
ios-autolayout
visual-prolog
machine-code
zimbra
matlab-compiler
incapsula
border-layout
android-databinding
kdevelop
abide
aura-framework
pyexcel
compiler-warnings
python-venv
servicebus
mef
hierarchical-clustering
hdpi
ear
openidm
px4
playframework-1.x
xamarin-test-cloud
computed-properties
eclipse-mars
normalisation
qtruby
queuing
laterjs
user-profile
abstract
gitk
database-project
jts
updating
page-flipping
consul-template
android-filterable
callfire
skview
firebase-tools
sony-xperia
system.io.packaging
os.walk
yosemite
zoneminder
parallel-port
atg-dynamo
code-smell
object-oriented-database
infor-eam
kernel-density
thucydides
nsnumber
codeigniter-form-helper
invalidoperationexception
motordriver
idtabs
hs-err
coderush-xpress
high-load

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App