简体   繁体   中英

C# connection string in web.config file

在我的代码隐藏页面中,如何访问存储在web.config文件中的连接字符串?

System.Web.Configuration.WebConfigurationManager.ConnectionStrings["YouConnStringName"].ConnectionString;

这需要引用System.Configuration.dll和System.Web.dll。

From comment on http://msdn.microsoft.com/en-us/library/ms178411.aspx

string c = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["myconnectionstringname"].ConnectionString;

Requires your project to reference to System.Web and System.Configuration. I had to actually add a reference to "System.Configuration" not just add a Using.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM