HEXAQ : A friendly question - answer site for IT professionals

C# - How to get connection string value from web.config file in asp net


0

I have stated learning ASP.NET from online videos and developing sample website.

I have to store record in database but do not know how to connect to database. Database connection string is added in web.config file and now want to know the way to access the connection string.

Can anybody help me to access it?

P.S. I am using Visual Studio 2010 and SQL Server 2008

Â
asked
 


≡ Total 1 Answer

0

If you are using ASP.NET 3.5 or higher you can refer these

Web.config

......  <configuration>    <connectionStrings>      <add name="Name" providerName="System.Data.SqlClient"        connectionString="Connection String;" />    </connectionStrings>  </configuration>......

.cs file

using System.Configuration.ConfigurationManager;......    string connString = ConfigurationManager.ConnectionStrings[Name];......
Â
replied


Enter your reply here
Answer Preview: