0

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

Colin Tong
  • 11
  • 3

3 Answers3

4

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.

Harminder
  • 2,209
  • 23
  • 20
2
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?

Community
  • 1
  • 1
IrishChieftain
  • 15,108
  • 7
  • 50
  • 91
0
System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString
Murali Murugesan
  • 22,423
  • 17
  • 73
  • 120