2

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?

-- EDIT --

The following connection statement is in my .dbml file:

<Connection Mode="AppSettings" ConnectionString="Data Source=PHILIP\SQLEXPRESS;
InitialCatalog=MyDatabase;Integrated Security=True" 
SettingsObjectName="MyDatabase_Data_Access_Layer.Properties.Settings" 
SettingsPropertyName="MyConnectionString" Provider="System.Data.SqlClient" />

2 Answers 2

4

On your Linq-to-SQL model (the *.dbml file), you should be able to bring up its properties. In the property grid, there is a Connection setting which allows you to specify where and how to store that connection information for Linq-to-SQL. This typically refers to your app.config/web.config. See my sample here:

alt text

(full size image at http://i43.tinypic.com/xazbrb.png )

There's nothing stopping you from using the very same connection string as your "normal" app uses - actually, that's quite a good idea, in fact!

So you should be able to basically change your SQL Server connection string in one place (in your app.config / web.config) and that should be all you need to do! Doesn't get much easier than that, does it?

Sign up to request clarification or add additional context in comments.

1 Comment

Verified courtesy of my last deployment cycle. Thanks again!
0

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?

That's what I do with LINQ-to-SQL, and it works.

1 Comment

@George - I've edited the question to include the Connection statement from the .dbml file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.