.NET 配置文件设置数据库连接属性

1.在web.config 网页应用程序 或者 app.config (桌面应用程序)中添加,好像是必须在<configuration>  </configuration> 下添加

  <appSettings>
      <add key="connstring" value="uid=sa;pwd=123456;database=bjtrc;server=(local)" />
    </appSettings>

2.添加引用

  using System.Configuration;

3.利用 string strConn = System.Configuration.ConfigurationManager.AppSettings["connstring"]; 读取对应的字符串

4.SqlConnection conn = new SqlConnection(strConn); 连接数据库

posted @ 2012-09-05 15:01  oftenlin  阅读(2588)  评论(0编辑  收藏  举报