我开发了一个winform的项目。软件打包时,想让用户在安装过程中输入数据库连接串。用户界面啥的都弄好了。在安装程序中想这样写入连接串:
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
string connString = "server="+ this.Context.Parameters["ghserver"].ToString().Trim()
+";uid="+ this.Context.Parameters["ghuid"].ToString().Trim()
+";password="+ this.Context.Parameters["ghpass"].ToString().Trim()
+";database="+ this.Context.Parameters["ghdb"].ToString().Trim()
+";";
this.saveValue("ConnString",connString.Trim());
}
//
//保存键值
//
public void saveValue(string KeyName, string KeyValue)
{
string appPath = Application.ExecutablePath+".config";
XmlDocument doc = new XmlDocument();
doc.Load(appPath);
XmlNode keyNode = doc.SelectSingleNode("/configuration/appSettings/add[@key='"+ KeyName + "']");
keyNode.Attributes["value"].Value = KeyValue;
doc.Save(appPath);
}
但是老是写不进去,不只是为什么。请高手指点,感激不尽!
public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
string connString = "server="+ this.Context.Parameters["ghserver"].ToString().Trim()
+";uid="+ this.Context.Parameters["ghuid"].ToString().Trim()
+";password="+ this.Context.Parameters["ghpass"].ToString().Trim()
+";database="+ this.Context.Parameters["ghdb"].ToString().Trim()
+";";
this.saveValue("ConnString",connString.Trim());
}
//
//保存键值
//
public void saveValue(string KeyName, string KeyValue)
{
string appPath = Application.ExecutablePath+".config";
XmlDocument doc = new XmlDocument();
doc.Load(appPath);
XmlNode keyNode = doc.SelectSingleNode("/configuration/appSettings/add[@key='"+ KeyName + "']");
keyNode.Attributes["value"].Value = KeyValue;
doc.Save(appPath);
}
但是老是写不进去,不只是为什么。请高手指点,感激不尽!
作者开发了一款WinForm应用程序,在安装过程中希望用户输入数据库连接字符串。通过自定义安装程序,试图将这些参数组合成连接字符串并写入配置文件,但遇到了无法写入的问题。
2214

被折叠的 条评论
为什么被折叠?



