tags:

views:

26

answers:

5

whats a good way to be able to keep 2 connection strings to SQL server in the web .comfig and have the app pick the correct one when its in the prod and dev servers?

i think i saw once some cool ways to keep variables like app settings holding two sets of values just like i am trying to do with my connection string to SQL... but i diont remmeber where i saw it..

can anyone help me figure this out?

my dev and prod servers vary by the port they use. so i have mysite.com and mysite.com:81

+1  A: 

I would recommend using completely separate config files for the two environments.

You can automate the choice of config file in your build/deployment process, if necessary.

LukeH
+1  A: 

Which version of ASP.NET are you using? In the latest release (ASP.NET 4.0) you can perform simple transformations on your Web.config file based on the build configuration of your project. For example, when you build in "Release" mode, then you can tell the Web.config.release file to transform your connection strings and replace them with the appropriate production versions.

There's a great article on MSDN about how to do this here: http://msdn.microsoft.com/en-us/library/dd465326.aspx

Scott Anderson
A: 

There is a tool for Visual Studio for deploying website called web deployment projects that will allow you to modify web.config based on the target build. It also provides other resources for deploying a website. The version for 2008 is here http://www.microsoft.com/downloads/en/details.aspx?familyId=0AA30AE8-C73B-4BDD-BB1B-FE697256C459&displaylang=en

There is also a version for 2005

Michael Gattuso
A: 

Check the accepted answer to my question here: http://stackoverflow.com/questions/94053/how-are-you-using-the-machine-config-or-are-you

I've used a very similar approach and it works nicely.

Chuck
A: 

One way to keep this simple is to use SQL server aliases. If both production and development servers are on different domains, you can give both SQL servers the same alias. You then you never need to change the Web.config.

In .NET 4, it's possible to have web.debug.config and web.release.config diffs.

x0n