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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -