From my DAL, How can i read a connection string from the web.config?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答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?
回答3:
System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString