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
Post a Comment