您的位置:首页 > 其它

How to get the "connection string" from web.config file

2008-08-28 23:58 507 查看
The connection strings stored in web.confing for asp.net2.0 are different from that in asp.net 1.0

The connectionstring is stored in the <appSettings> for ASP.net1.0 whereas it is in the <connectionStrings> section for ASP.net2.0

<appSettings>

<!-- Database connection string -->

<add key="ConnStr" value="Data Source=(local);database=SCardDB;UID=sa;Password=;Persist Security Info=True;"/>

</appSettings>

<connectionStrings>

<remove name="LocalSqlServer" />

<add name="LocalSqlServer" connectionString="Data Source=myDBServer;database=myDB;Integrated Security=True;" providerName="System.Data.SqlClient"/>

</connectionStrings>

I know how to get the connectionstring from web.config of asp.net1.0.

SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["ConnStr"]);

How to get it from web.config of asp.net2.0?

string strConnString = ConfigurationManager.ConnectionStrings["LocalSqlServer"].ConnectionString;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: