从我的DAL中,如何从web.config中读取连接字符串?从web.config文件读取值?
0
A
回答
4
可以使用WebConfigurationManager来读取web.config中的连接字符串值
代码示例:
using System.Configuration;
string connString = WebConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
确保已将System.configuration引用添加到DAL。
2
using System.Configuration;
static string connectionString =
ConfigurationManager.ConnectionStrings["MyConn"].ConnectionString;
悠只需要WebConfigurationManager
如果有使用数据连接字符串在您的项目有几个Web.config文件中:
What's the difference between the WebConfigurationManager and the ConfigurationManager?
0
System.Configuration.ConfigurationManager.ConnectionStrings["connStr"].ConnectionString
相关问题
- 1. 读取web.config文件的值
- 2. 从Javascript读取web.config值
- 3. AppSetting值是从内存还是从web.config文件读取?
- 4. 无法读取web.config文件
- 5. 如何从JavaScript文件中的web.config中读取关键值?
- 6. 从Web.Config读取使用configSource文件的值
- 7. 从web.config获取价值到XSLT文件
- 8. 通过CSS读取Web.Config值
- 9. 可以从外部xml文件读取web.config文件吗?
- 10. 从resx文件读取值?
- 11. 从xml文件读取值
- 12. Java - 从文件读取值?
- 13. 从javascript中读取web.config
- 14. 从web.config读取数据
- 15. 如何从.tt文件(T4模板)从web.config中读取appSetting
- 16. 阅读Ninject WithConstructorArguments从Web.config文件
- 17. Java从文本文件中读取值
- 18. C从文本文件中读取值
- 19. 从文本文件中读取值?
- 20. 无法从我的ASP.NET web.config文件中读取<appSetting>的值
- 21. 如何从ASP.NET应用程序的web.config文件中读取设置值?
- 22. 如何在JS文件中使用JavaScript从web.config中读取会话超时值
- 23. 试图读取web.config文件从Windows服务
- 24. WCF从web.config文件读取端点行为
- 25. ConfigurationManager.AppSettings [Key]每次都从web.config文件读取?
- 26. 读取web.config中值是在JavaScript
- 27. smtpClient不读取Web.config
- 28. 从web.config文件获取初始目录
- 29. 使用jquery从json文件读取值
- 30. 从文件txt或xml读取值
我在发帖之前做过搜索,但完全忘了将System.configuration引用添加到我的DAL中。 –