App.config


在解决方案中增加一窗口选择xml文件,并将名称改为app.config.其内容设置如下:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <appSettings>
    <add key="source" value="Server=localhost;uid=sa;pwd='fang';database=khgx;" />
    </appSettings>
  </configuration>
请在引用中添加-System.configuration不然程序会提示错误。在程序中就可以这样调用:
private string source = System.Configuration.ConfigurationManager.AppSettings["source"];
conn = new SqlConnection(source);
 
打包安装后,可以直在安装的机器上面接修改配置文件,进行数据库连接。

posted on 2008-10-20 21:26  cococ  阅读(1513)  评论(1编辑  收藏  举报

导航