在.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();
在WIN7下,是不是要以管理员身份运行此程序?
你看下是不是数据库连接的问题
跟踪一下代码,看看有什么错误信息