在页面后面我的代码,我怎么访问存储在我的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”不只是添加使用。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top