system.configuration.configurationmanager.connectionstrings为什么给我不同的连接字符串 [英] why system.configuration.configurationmanager.connectionstrings is giving me different connection string
问题描述
在我的web.config文件中我只定义了一个连接字符串,但system.configuration.configurationmanager.connectionstrings正在向我显示2.
system.configuration.configurationmanager .connectionstrings [0] .connectionstrings =" datasource =。\\sqlexpress"
我没有在任何地方定义。仅供参考我创建edmx模型时。我使用了这个字符串,但后来我删除了它。但它仍然显示。
在web.config中添加connectionString的名称属性,然后:
ConfigurationManager.ConnectionStrings [ Con_Name]。ConnectionStrings
让我知道它是否有效!
我想你会找到答案'为什么会这样?'这里:
ASP.NET开发人员应该了解的关于Web.config继承和覆盖的10件事情[ ^ ]
in my web.config file i have defined only one connection string but system.configuration.configurationmanager.connectionstrings is showing me 2.
system.configuration.configurationmanager.connectionstrings[0].connectionstrings="datasource=.\\sqlexpress"
which i didn't define anywhere. FYI when i created the edmx model. i used this string but later i removed it.but still it appears.
Add name attribute for your connectionString in web.config then :
ConfigurationManager.ConnectionStrings["Con_Name"].ConnectionStrings
Let me know if it works!
I think you will find your answer of 'Why it happens?' here:
10 Things ASP.NET Developers Should Know About Web.config Inheritance and Overrides[^]
这篇关于system.configuration.configurationmanager.connectionstrings为什么给我不同的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!