111,129
社区成员
发帖
与我相关
我的任务
分享sa登陆:
"Data Source=.;Initial Catalog=数据库;User ID=sa,pwd=;"; windows登陆
Data Source=.;Initial Catalog=数据库;Integrated Security=True
/// <summary>
/// 修改web.config的<connectionStrings>章节
/// </summary>
/// <returns></returns>
private bool WriteConWebConfig()
{
System.IO.FileInfo FileInfo = new System.IO.FileInfo(Setupdir + "/web.config");
if (!FileInfo.Exists)
{
throw new InstallException("Missing config file :" + Setupdir + "/web.config");
}
System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
xmlDocument.Load(FileInfo.FullName);
bool FoundIt = false;
foreach (System.Xml.XmlNode Node in xmlDocument["configuration"]["connectionStrings"])
{
if (Node.Name == "add")
{
if (Node.Attributes.GetNamedItem("name").Value == "StandardLMS_ConnectionString")
{
if (AdminName != "" && AdminPwd != "")
{
Node.Attributes.GetNamedItem("connectionString").Value = String.Format("Persist Security Info=False;Data Source={0};database={1};User ID={2};Password={3};Packet Size=4096;Pooling=true;Max Pool Size=100;Min Pool Size=1", ServerName, DBName, AdminName, AdminPwd);
}
else
{
Node.Attributes.GetNamedItem("connectionString").Value = "Server=" + ServerName + ";Database=" + DBName + ";Integrated Security=true";
}
FoundIt = true;
}
}
}
if (!FoundIt)
{
throw new InstallException("Error when writing the config web.config");
}
xmlDocument.Save(FileInfo.FullName);
return FoundIt;
}