In this post I will describe how to use both a local connection string and a remote connection string at the same time in a Visual Studio 2010 project.
First of, what you need to do is get some grip of the concept of builds for your project. There are two default build types out of the box, debug and release.
The difference between Debug and Release
The main difference between the both is that Release build strips out all debug information in from your project.
For example, in your web.config for a debug build this section would look like this.
<system.web>
<compilation debug=“true“ targetFramework=“4.0“>
And for the release build it would be like the following.
<system.web>
<compilation targetFramework=“4.0“>
Therefore when pressing debug (F5) in Visual Studio you will be running your code using the web.config from debug mode.
That is debug=“true” is in set.
This is very important when it comes to the use of two connection strings, one for your local server and one for the production server.
To avoid the time consuming and unsecure process of having to rename a connection string before publish to production (yes we have
all done that before), Visual Studio 2010 comes with a new feature called Add Config Transforms. If you right-click the web.config you see
Add Config Transforms in the context menu.

Selecting this will create two “partial” web.config files. One named Web.Debug.config and one Web.Release.config.

If your project contains others then the default build types they too will get a “partial” Web.<name>.config file.
If we open up the Web.Debug.config file it looks like this.
<?xml version=“1.0“?>
<configuration xmlns:xdt=“http://schemas.microsoft.com/XML-Document-Transform“>
<system.web>
</system.web>
</configuration>
What you can do here is set the connection string properties and the custom error properties. This will then use the
web.config as a template and replace the nodes from either the Web.Debug.config or Web.Release.config.
So when we later publish our project we can choose to publish as a release build and we will then have the connection string
properties set in Web.Release.config file in our Web.config file. No more hassle of remember to rename property names. =)