如何在安装程序中将数据库连接串写入App.config

作者开发了一款WinForm应用程序,在安装过程中希望用户输入数据库连接字符串。通过自定义安装程序,试图将这些参数组合成连接字符串并写入配置文件,但遇到了无法写入的问题。
我开发了一个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);  
  }  
  但是老是写不进去,不只是为什么。请高手指点,感激不尽!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值