app.config中默认的配置如下:
app.config中默认的配置如下:
访问数据库是成功了的!
我在项目初始时通过代码修改该配置,代码如下:
(省略部分)
string con = "server=" + read[0] + ";user id=" + read[1] + ";password=" + read[2] + ";persistsecurityinfo=True;database=zhdmk;allowuservariables=True"";
string ConString = "metadata=res://*/zh.csdl|res://*/zh.ssdl|res://*/zh.msl;provider=MySql.Data.MySqlClient;provider connection string="" + con;
ConnectionStringSettings mySettings =
new ConnectionStringSettings("zhdmkEntities", ConString, "System.Data.EntityClient");
// 打开可执行的配置文件*.exe.config
Configuration config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (ConfigurationManager.ConnectionStrings["zhdmkEntities"] != null)
{
config.ConnectionStrings.ConnectionStrings.Remove("zhdmkEntities");
}
config.ConnectionStrings.ConnectionStrings.Add(mySettings);
// 保存
config.Save(ConfigurationSaveMode.Modified);
// 强制重新载入
ConfigurationManager.RefreshSection("ConnectionStrings");
访问数据出现异常:
不懂的不要说话!!!!!!!!!!!!!!!
展开