In my C#-WinForms-application (.Net 3.5, VS2008) I read the App.Config using:
Configuration myConfig =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
App.config contains two connection strings in the connectionStrings-Section:
<connectionStrings>
<add name="db1" connectionString="connection1"
providerName="System.Data.SqlClient"/>
<add name="db2" connectionString="connection2"
providerName="System.Data.SqlClient" />
</connectionStrings>
(connection strings abreviated for readability)
But when I loop through the ConnectionStringsCollection I find that it has three entries instead of the expected two. The additional entry points to a database called “aspnetdb.mdf” on a local SqlExpress-Server. I can’t remember adding this anywhere, I can’t find it as a literal value in my project files. Watching the collection with the debugger I find that my connection strings have the app.config as source. The additional string has null as source, so I think .net conjurs it up from somewhere.
How can I get rid of this entry, or failing that how can I tell the configuration manager to only use the connection strings in the app.config?
The aspnetdb.mdf comes from the default connection strings collection, remove it by adding
to the top of your element.