From my DAL, How can i read a connection string from the web.config?
Asked
Active
Viewed 1,386 times
0
-
I did search prior to posting but totally forgot to add the System.configuration reference to my DAL. – Colin Tong Oct 23 '12 at 12:25
3 Answers
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