In Asp.Net 2.0 and Asp.Net 3.5 we have a Tag Inside Web.config file that is ConnectionString Tag.
<connectionStrings>
<add name=”MyConnString” connectionString=”Server=ServerName;Database=DBName;
Uid=UserId;Pwd=Passwd;” providerName=”System.Data.SqlClient“/>
connectionStrings>
Now to get the Connection string defined in the web.config file you have to do like this in your .cs file. Below code is based on C#
string Conn= ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString;
In Vb.NET
Dim Conn as String = ConfigurationManager.ConnectionStrings(“MyConnString“).ConnectionString
<connectionStrings>
<add name=”MyConnString” connectionString=”Server=ServerName;Database=DBName;
Uid=UserId;Pwd=Passwd;” providerName=”System.Data.SqlClient“/>
connectionStrings>
Now to get the Connection string defined in the web.config file you have to do like this in your .cs file. Below code is based on C#
string Conn= ConfigurationManager.ConnectionStrings["MyConnString"].ConnectionString;
In Vb.NET
Dim Conn as String = ConfigurationManager.ConnectionStrings(“MyConnString“).ConnectionString
No comments:
Post a Comment