首页 > 数据库 >3_将数据库连接方式写到配置文件中(转载)

3_将数据库连接方式写到配置文件中(转载)

时间:2022-09-02 11:11:38浏览次数:82  
标签:配置文件 数据库 ConnectionString 转载 config 连接

连接sqlserver的连接字符串

  1. asp.net 项目配置文件:Web.config
    winfrom项目配置文件:App.config
<configuration>
 <!--数据库连接-本地-->
 <!--<connectionStrings>
    <add name="connectionString"
         connectionString="server=.;Initial Catalog=ss;Integrated Security=True"
         providerName="System.Data.SqlClient"/>
  </connectionStrings>-->
  
  <!--数据库连接-sa-->
  <connectionStrings>
    <add name="ConnectionString"
         connectionString="Data Source=10.xx.xx.xx;Initial Catalog=D_xx;User ID=sa;Password=sa;"
         providerName="System.Data.SqlClient" />
  </connectionStrings>

</configuration>

  1. 读取
 using System.Configuration;//引用
 private static string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;  

转自
csdn

标签:配置文件,数据库,ConnectionString,转载,config,连接
From: https://www.cnblogs.com/fhzmasl/p/16649117.html

相关文章