在web.config文件C#连接字符串
-
22-07-2019 - |
题
在页面后面我的代码,我怎么访问存储在我的web.config文件中的连接字符串?
解决方案
System.Web.Configuration.WebConfigurationManager.ConnectionStrings["YouConnStringName"].ConnectionString;
此要求System.Configuration.dll和System.Web.dll中引用。
其他提示
从上 http://msdn.microsoft.com/en-us评论/library/ms178411.aspx
string c = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myconnectionstringname"].ConnectionString;
需要您的项目中引用到的System.Web和System.Configuration。我不得不实际添加引用“System.Configuration”不只是添加使用。
不隶属于 StackOverflow