Colin Tong
Colin Tong

Reputation: 11

Reading value from web.config file?

From my DAL, How can i read a connection string from the web.config?

Upvotes: 0

Views: 1400

Answers (3)

IrishChieftain
IrishChieftain

Reputation: 15253

using System.Configuration;

static string connectionString = 
    ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;

Yuu only need WebConfigurationManager if there are several Web.Config files in your project using data connection strings:

What's the difference between the WebConfigurationManager and the ConfigurationManager?

Upvotes: 2

Harminder
Harminder

Reputation: 2229

You can use the WebConfigurationManager to read connection string value from web.config

Code Example:

using System.Configuration;

string connString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

Make sure you have added the System.configuration reference to your DAL.

Upvotes: 4

Murali Murugesan
Murali Murugesan

Reputation: 22619

System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString

Upvotes: 0

Related Questions