2

We have a different set of connection strings in our config file as follows.

<!-- TEST CONNECTION STRING -->
<!--
<add name="fooConnection" connectionString="Data Source=Test_server;Initial Catalog=foo_dbTEST;User ID=foo_user;Password=abc1234;"/>
<add name="barConnection" connectionString="Data Source=Test_server;Initial Catalog=bar_dbTEST;User ID=bar_user;Password=abc1234;"/>
<add name="chewConnection" connectionString="Data Source=Test_server;Initial Catalog=chew_dbTEST;User ID=chew_user;Password=abc1234;"/>
-->

<!-- LIVE CONNECTION STRING -->

<add name="fooConnection" connectionString="Data Source=Live_server;Initial Catalog=foo_dbTest;User ID=fooTest_user;Password=abc1234;"/>
<add name="barConnection" connectionString="Data Source=Live_server;Initial Catalog=bar_Testdb;User ID=barTest_user;Password=abc1234;"/>
<add name="chewConnection" connectionString="Data Source=Live_server;Initial Catalog=chew_Test;User ID=chewTest_user;Password=abc1234;"/>

<!-- Local DEV CONNECTION STRING -->
<!--
<add name="fooConnection" connectionString="Data Source=MyDoombaPC;Initial Catalog=fooDEVdbTest;User ID=foouser;Password=abc1234;"/>
<add name="barConnection" connectionString="Data Source=MyDoombaPC;Initial Catalog=barDEVdb;User ID=barTestuser;Password=abc1234;"/>
<add name="chewConnection" connectionString="Data Source=MyDoombaPC;Initial Catalog=chewDEVdb;User ID=chewuser;Password=abc1234;"/>
-->

When I need to change from, for example, live to test I move the XML comments from the Test section to the live section. Is there a more elegant way of doing this using Visual Studio 2010?

Just to be clear this is not a requirement of the application once it is in production, this is for developers to switch between different database connection string sets.

How do others approach this?

1
  • See a similar question and answer here Commented Aug 14, 2012 at 12:17

1 Answer 1

3

You could use the web.config transformation : web.config Transformation

This will allow you to have seperate config files for both debug and release and have different setting in each.

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

Comments

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.