tomfumb
tomfumb

Reputation: 3759

.NET 2.0 App.Config connection strings includes unwanted SQLExpress default

I'm using a connectionStrings section within an app.config file in a .NET 2.0 project. The config section contains two connection strings I have defined.

When I retrieve the ConnectionStringSettingsCollection it has a count of 3. The 0th entry is a connection to SQLExpress

Name: LocalSqlServer,
ConnectionString: data source=.\\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true

Why is this connection being included even though it's not in my app.config, and how can I get rid of it? This code will be running on desktop machines that I have no access to - so how can I prevent any more local connections from randomly showing up at runtime? I can't see any properties on the connection that indicate it's any different from the two I defined.

Upvotes: 3

Views: 533

Answers (1)

to StackOverflow
to StackOverflow

Reputation: 124726

It's defined in machine.config. To get rid of it, use:

<connectionStrings>
    <clear/>
    <add ... >
</connectionStrings>

As a general rule, sections that have <add> and <remove> elements (e.g. appSettings, connectionStrings and the provider configuration sections) also have a <clear> element, which you can use if you don't want to inherit elements from a higher level web.config or machine.config file.

Upvotes: 6

Related Questions