Computer
Computer

Reputation: 2227

Change configuration file when using Linq to SQL

I've read a few links but most are in relation to when deploying or i've missed a trick in the middle so dont fully understand hence asking the below question......

I have a live, test and local environment (all have their own individual connection strings). I create a solution with 2 projects (for example) 1 is a ASP .Net website and other is a Class Library. Within the class library i add a Linq to SQL and add a connection to it. The connection string is stored in an app.config file.

What i would like to do is be able to switch between the environments so the connection string is updated to reflect the environment i am using without having to manually type in the connection string. I've seen this done but not sure how to do it myself? Im using VS2010. Could anyone advise or point me in the right direction?

Thanks

Upvotes: 0

Views: 105

Answers (1)

LukeHennerley
LukeHennerley

Reputation: 6444

You could potentially use #if DEBUG and have two connections strings in your app.config - one called Test one called Live - I would suspect that debugging would indicate that you are in the test environment and on release you would be live.

Please refer to this link http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx

Another option is to simply have an input at some point to indicate which environment the application is running on - you could do this with a checkbox or radio button or even through appSettings in app.config by specifying ConnectionMode and setting it to 1 or 2 if the setting reads 1, then use the test connection string, if it reads 2 Live connection string.

Upvotes: 1

Related Questions