"Cleanly" Deploying an ASP.NET Application with LINQ to SQL Server

Posted by Bob Kaufman on Stack Overflow See other posts from Stack Overflow or by Bob Kaufman
Published on 2010-04-15T18:49:03Z Indexed on 2010/04/15 18:53 UTC
Read the original article Hit count: 272

In my development environment, my SQL Server is PHILIP\SQLEXPRESS. In testing, it's ANNIE, and the live environment will have a third name yet to be determined. I would have assumed that updating the following statement in web.config would have been enough:

<add name="MyConnectionString"providerName="System.Data.SqlClient" 
connectionString="Data Source=PHILIP\SQLEXPRESS;Initial Catalog=MyDtabase;Integrated Security=True" />

When using SqlConnection, SqlCommand, SqlDataReader and friends, that's all it took. Using LINQ, it doesn't seem to work that nicely. I see the servername repeated in my .dbml file as well as in Settings.settings. After changing it in all of those places, I get it to work. However if I'm doing a few deployments per day during testing, I want to avoid this regimen.

My question is: is there a programmatic solution for LINQ to SQL that will allow me to specify the connection string once, preferably in web.config, and get everybody else to refer to it?

© Stack Overflow or respective owner

Related posts about deployment

Related posts about sql-server