从web.config中读取数据库连接串
黑色星空 :: 黑色星空 :: 网络攻防(行千里路,读万卷书) :: 攻防转载
第1页/共1页
从web.config中读取数据库连接串
、 利用System.Web.Configuration类
读取代码:
String strconn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["AddressBookConnectionString"].ConnectionString;
或
string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["AddressBookConnectionString"].ConnectionString;
web.config中的配置代码:
<connectionStrings>
<add name="AddressBookConnectionString" connectionString="Data Source=PC- 20090911ZYIV;Initial Catalog=addressBook;User ID=sa;Password=sa" providerName="System.Data.SqlClient" />
</connectionStrings>
2、 利用System.Configuration类
读取代码:
string strconn = System.Configuration.ConfigurationManager.AppSettings["AddressBookConnectionString"].ToString();
web.config中的配置代码:
<appSettings>
<add key="AddressBookConnectionString" value="Data Source=PC-20090911ZYIV;Initial Catalog=addressBook;User ID=sa;Password=sa"/>
</appSettings>
读取代码:
String strconn = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["AddressBookConnectionString"].ConnectionString;
或
string strconn = System.Configuration.ConfigurationManager.ConnectionStrings["AddressBookConnectionString"].ConnectionString;
web.config中的配置代码:
<connectionStrings>
<add name="AddressBookConnectionString" connectionString="Data Source=PC- 20090911ZYIV;Initial Catalog=addressBook;User ID=sa;Password=sa" providerName="System.Data.SqlClient" />
</connectionStrings>
2、 利用System.Configuration类
读取代码:
string strconn = System.Configuration.ConfigurationManager.AppSettings["AddressBookConnectionString"].ToString();
web.config中的配置代码:
<appSettings>
<add key="AddressBookConnectionString" value="Data Source=PC-20090911ZYIV;Initial Catalog=addressBook;User ID=sa;Password=sa"/>
</appSettings>
黑色星空 :: 黑色星空 :: 网络攻防(行千里路,读万卷书) :: 攻防转载
第1页/共1页
您在这个论坛的权限:
您不能在这个论坛回复主题