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

Why is my locally declared variable not being recognized in the finally block?
Comparing two different types with Entity Framework
loginview shows “welcome system-name/administrator” and logout for the first time page load
How to abort another thread in .NET, when said thread is executing Console.ReadLine?
OrderBy / ThenBy looping - nested Lists in C#
How to login external web site from asp.net web page? [closed]
ListPicker for WPF?
How to notify user of new message?
WPF Treeview Bindings
How do you iterate through JSON object in an ASP.NET MVC controller?
Explicitly specifying the TaskScheduler for an implicitly scheduled method
DataGridView setting row height doesn't work
Retrieving data from webservice & displaying it in a listbox
How to detect double click on window title in c#
How Can i display the output of SQL “PRINT” Command in C#?
How to get the (.lnk) shortcut filepath in a program which started by the shortcut?

Categories

HOME
oop
youtube-api
msbuild
swift3
stanford-nlp
ssh
openacc
xamarin.forms
data-modeling
terminal
glympse
install
wkhtmltopdf
mongoimport
camunda
cakephp-2.0
glibc
jq
opengraph
inline-assembly
connection-pooling
rvm
android-wear-2.0
poisson
continuous-fourier
pydub
orgchart
utc
resx
emr
cqlsh
ipython-parallel
semantic-ui-react
paper-trail-gem
key-bindings
spring-oauth2
qt-designer
oracle-nosql
n1ql
incapsula
headphones
azure-vm-scale-set
border-layout
nsdateformatter
google-chrome-console
peerjs
text-extraction
cancan
riemann
androiddesignsupport
totalview
multi-select
scrollmagic
robotc
huawei
ownership
firebase-polymer
mac-app-store
dimensionality-reduction
jigsaw
angularfire
razorengine
phpdesigner
mod
paypal-subscriptions
cexception
mojolicious
database-project
transport
grails-3.0.9
connection-timeout
static-files
crtdbg.h
pysvn
cordova-3
random-access
clearcanvas
dirname
javacompiler
disparity-mapping
scjp
atg-dynamo
debuggervisualizer
android-relativelayout
azure-caching
farpoint-spread
slimscroll
xtify
dylan
ie-developer-tools
kohana-orm
violation
maven-webstart-plugin
pyxplot
wpd
asp.net-4.0
reference-manual
auctex
metapost
ncml
aspmenu-control
advanceddatagrid
visual-leak-detector
clgeocoder
rjs
pex-and-moles
flexbuilder
digg
jexcelapi
zipstream
datarelation
atmega16
httpbrowsercapabilities
stackless

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