在.net framework 3.5下做的winform程序,在XP下,程序运行时修改app.config成功。在win7下程序运行修改app.config不成功,大家又遇到这种问题的吗? 是系统的原因 还是我程序的原因啊
代码是:string newName = "conn"; string ProviderName = "System.Data.SqlClient"; string newConn = "Data Source=" + textBox5.Text.ToString() + "," + textBox1.Text.ToString() + ";Initial Catalog=XtCRM ; User ID=" + textBox3.Text.ToString() + ";Password=" + textBox4.Text.ToString() + ""; bool isModified = false; if (ConfigurationManager.ConnectionStrings["conn"] != null) { isModified = true; } ConnectionStringSettings mysettings = new ConnectionStringSettings(newName, newConn, ProviderName); Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (isModified) { config.ConnectionStrings.ConnectionStrings.Remove("conn"); } config.ConnectionStrings.ConnectionStrings.Add(mysettings); config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection("connectionStrings"); MessageBox.Show("配置成功!"); Application.Restart();
- 3 回答
- 0 关注
- 832 浏览
添加回答
举报
0/150
提交
取消