首页 > 代码库 > c#引用web.config中的ConnectionString

c#引用web.config中的ConnectionString

c#引用web.config中的ConnectionString

<connectionStrings>
  <add name="JKXTConnectionString" connectionString="Data Source=CHF;Initial Catalog=JKXT;User ID=sa" providerName="System.Data.SqlClient" />
  <add name="JGXTConnectionString" connectionString="Data Source=CHF;Initial Catalog=JGXT;User ID=sa" providerName="System.Data.SqlClient" />
 </connectionStrings>

 

<connectionStrings>
    <add name="DB_EMSConnectionString" connectionString="Data Source=85DDBBBFA5A34F9;Initial Catalog=DB_EMS;Integrated Security=True" providerName="System.Data.SqlClient" />

</connectionStrings>


获取的办法是:
ConfigurationManager.ConnectionStrings["JGXTConnectionString"].ConnectionString;

或者这么写web.config
 <appSettings>
  <add key="connectionstring" value="http://www.mamicode.com/Data Source=CHF;Initial Catalog=JGXT;User ID=sa"/>
 </appSettings>

 

<appSettings>

<add key="DbHelperProvider" value="http://www.mamicode.com/System.Data.SqlClient"/>

<add key="DbHelperConnectionString" value="http://www.mamicode.com/Data Source=85DDBBBFA5A34F9;Initial Catalog=DB_EMS;Integrated Security=True"/>

</appSettings>


获取办法是:
ConfigurationSettings.AppSettings["JGXTConnectionString"];

引用using System.Configuration;

c#引用web.config中的ConnectionString