Changing your app.config at runtime
C#, Programming December 7th, 2009To change the app.config connectionstrings at runtime you can use the following code:
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var connectionStringSettings = new ConnectionStringSettings("ConnectionString", _arguments["connectionString"], "System.Data.SqlClient");
config.ConnectionStrings.ConnectionStrings.Add(connectionStringSettings);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("connectionStrings");
with thx to Johlero for the R&D.
Recent Comments