我想在运行时在 app.config 中更改连接字符串
我写的代码如下:
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");
但 app.config 不会改变!