App.config - LocalSqlServer connection string

It is possible to have more than just the LocalSqlServer in your Machine.config. e.g. I just ran my app on a computer with a MySql connection in Machine.config

You can use the ElementInformation property of the ConnectionStringSetting to determine where it came from:

foreach (ConnectionStringSettings c in ConfigurationManager.ConnectionStrings)
{
    ElementInformation elementInfo = c.ElementInformation;
    String source = elementInfo.Source;

    if (source == null)
    {
        //Machine.config
    } 
    else
    {
        Console.WriteLine("{0} {1} {2}", c.Name, elementInfo.Source, c.ConnectionString);
    }
}

It is defined in the Machine.config global file located at

"C:\Windows\Microsoft.NET\Framework\v4.0.30319\CONFIG".

It is generated when you install the NET.Framework and is needed by tools that work on the ASPNETDB

If you don't need it, you could try to add this to your app.config

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

or also

<connectionStrings>
<remove name="LocalSqlServer" />

I really suggest to not change anything in Machine.Config unless you know the side effects.

Tags:

Vb.Net