在我的C#-WinForms-application(.Net 3.5,VS2008)中,我使用以下方法阅读App.Config:
Configuration myConfig =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
Run Code Online (Sandbox Code Playgroud)
App.config在connectionStrings-Section中包含两个连接字符串:
<connectionStrings>
<add name="db1" connectionString="connection1"
providerName="System.Data.SqlClient"/>
<add name="db2" connectionString="connection2"
providerName="System.Data.SqlClient" />
</connectionStrings>
Run Code Online (Sandbox Code Playgroud)
(为了便于阅读,连接字符串被删除)
但是当我遍历ConnectionStringsCollection时,我发现它有三个条目而不是预期的两个条目.附加入口指向本地SqlExpress-Server上名为"aspnetdb.mdf"的数据库.我不记得在任何地方添加它,我在项目文件中找不到它作为文字值.使用调试器观察集合我发现我的连接字符串将app.config作为源.附加字符串作为源为null,所以我认为.net从某处汇总了它.
我怎样才能摆脱这个条目,或者我怎么能告诉配置管理器只使用app.config中的连接字符串?
你检查了machine.config吗?
(找到%SystemRoot%\Microsoft.NET\Framework\v2.0.50727\CONFIG64位使用Framework64.)