Application parameters in the database

I want to centrally find all the settings of my application in the database. I have a database object that stores app.settings settings in an XML column. I would like my application to read this object and then parse the XML column in its own application settings. Is there an easy way to randomly read an XML object in your current settings?

+1


source to share


3 answers


Read the object from the XML object and then through your code you can save your config file as:

Configuration configFile = WebConfigurationManager.OpenWebConfiguration ("~");

AppSettingsSection AppSection = configFile.GetSection ("AppSettings") as AppSettingsSection;

AppSection.Settings.Add (new KeyValueConfigurationElement ("SMTP", "Mail.bhaidar.net"));

configFile.Save ();



The above code will add the following line to the appSettings section.

<appSettings>

< add key="SMTP" value="mail.bhaidar.net" / >

      

</appSettings>

0


source


I don't know if you can change the application settings at runtime, what I know you can do is create an appsettings section as shown here and you have a relay application that loads the correct xml for you, the file settings save the file and then launch the desire app.



0


source


It might be possible, but in case it isn't, I like to do the following:

  • Never call ConfigurationaManager directly - wrap the whole thing in your own settings class and call it.
  • Then you can place your settings wherever you want and change strategies flexibly. You can do each row setting in the database table, use the normal web.config application settings, or switch some other method along the way.
0


source







All Articles