无法从web.config中找到连接字符串 [英] Not able to find Connection string from web.config

查看:66
本文介绍了无法从web.config中找到连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述







当我尝试使用来自Web.Config的连接字符串时,它显示为null ...



我使用

Hi,


when I am trying to use connection string from Web.Config , it is showing null...

I used

string conStr = WebConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;






and

string conStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;





请帮助





谢谢



Please Help


Thank You

推荐答案

检查您是否提到过web.config文件中ConnectionString标签或AppSettings标签下的详细信息。



如果连接字符串在ConnectionString标签中,则使用此



Check whether you have mentioned the details under ConnectionString Tag or AppSettings Tag in your web.config file.

If connection string is in ConnectionString Tag then use this

string conStr = ConfigurationManager.ConnectionStrings["ConnectionStringName"].ConnectionString.ToString();





如果连接字符串在AppSettings标签中,那么使用这个





If connection string is in AppSettings Tag then use this

string conStr = ConfigurationManager.AppSettings["ConnectionStringName"].ToString();


System.Configuration.ConfigurationManager.
    ConnectionStrings["connectionStringName"].ConnectionString;







注意:connectionStringName必须与webconfig相同




note:"connectionStringName" must be same as in webconfig


检查web.config是在正确的位置?

你有任何web.config(它覆盖主web.config)在与你的页面相同的文件夹中吗?
Check if the web.config is at its right location?
Do you have any web.config (which overrides main web.config) in the same folder as that of your page?


这篇关于无法从web.config中找到连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆