从我的DAL,如何从web.config中读取连接字符串?
答案 0 :(得分:4)
您可以使用WebConfigurationManager从web.config
读取连接字符串值代码示例:
using System.Configuration;
string connString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
确保已将System.configuration引用添加到DAL。
答案 1 :(得分:2)
using System.Configuration;
static string connectionString =
ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
如果您的项目中有多个Web.Config文件使用数据连接字符串,则Yuu只需要WebConfigurationManager
:
What's the difference between the WebConfigurationManager and the ConfigurationManager?
答案 2 :(得分:0)
System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString