BeanSoftware Logo
 

 
ASP.NET Database Search Control
 
 

 
 Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact

How To Read Connection String From Web.Config File?

Let say you have connection string stored in web.config file, like this:

<connectionStrings>
    <clear />
    <add name="SqlServerConnStr" connectionString="server=MySqlServer;Initial Catalog=MyDatabase;User ID=myUserName;Password=myPassword" providerName="System.Data.SqlClient"/>
</connectionStrings>

To read connection string from web.config with ASP.NET server side code, you can use simple code line like this:

[ C# ]

string myConnStr = ConfigurationManager.ConnectionStrings["SqlServerConnStr"].ConnectionString;

[ VB.NET ]

Dim myConnStr As String = _
ConfigurationManager.ConnectionStrings("SqlServerConnStr").ConnectionString



Related articles:

1. Cookies in ASP.NET
2. CAPTCHA - prevent bots and automatic submissions in ASP.NET
3. Who Ever Said Freelancing Was Easy?

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.