.net – Keep ConnectionString in LINQ designer file

linqnet

Whenever I drop a new database object from server explorer into the dbml, Visual Studio replaces the connection string in the designer file with a new one that it automatically adds to the connection strings in my config file. They both have exactly the same parameters, just different names.

How do I force Visual Studio to use and keep the connection string I already have?

For example, in the dbml-designer.cs, I have this:

base(global::System.Configuration.ConfigurationManager.ConnectionStrings["ConnString1"].ConnectionString, mappingSource)

which is automatically generated. In my config file, I have:

<add name="DefaultConnString" connectionString="EXACTLYTHESAME"
    providerName="System.Data.SqlClient" /> <add name="ConnString1" connectionString="EXACTLYTHESAME"
    providerName="System.Data.SqlClient" />

Where ConnString1 is added automatically whenever I drag a database object to the dbml.

I want the designer.cs to use DefaultConnstring.

Best Answer

There's a good post that pretty much explains your options here:

http://blog.jongallant.com/2007/11/linq-web-app-connection-strings.html#.UGA8Q42PUg0