c# - Not Change app.config -


i want change connection string @ runtime in app.config

the code wrote follows:

var config = configurationmanager.openexeconfiguration(configurationuserlevel.none); connectionstringssection connectionstringssection = (connectionstringssection)config.getsection("connectionstrings"); connectionstringssection.connectionstrings["test"].connectionstring = "sadasd"; //config.connectionstrings.sectioninformation.forcesave = true; config.save(); configurationmanager.refreshsection("connectionstrings"); 

but app.config not change!

you can try method used me , worked me on winforms , mysql project :

 private void editconstring(string connname, string user, string pwd, string server,string database)         {             var config = configurationmanager.openexeconfiguration(configurationuserlevel.none);             var connectionstringssection = (connectionstringssection)config.getsection("connectionstrings");             connectionstringssection.connectionstrings[connname].connectionstring = "server=" + server + ";user id=" + user + ";password=" + pwd + ";database=" + database + ";connectiontimeout = 60;allow 0 datetime=true";             config.save();             configurationmanager.refreshsection("connectionstrings");         } 

good luck!


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -