1

In my web.config file, I have a connection string to connect my development database.

 <connectionStrings>
<add name="MembershipDB" connectionString="Data Source=DebugSQL;Initial Catalog=PortalAccess;Integrated Security=True;Application" providerName="System.Data.SqlClient"/>

When I publish the web site to my production server, I just change the Data Source name. When I test it, then I switch it again, is it stupid?

  • 4
    It is not stupid, since it works, however it could be better. Since you are using Visual Studio, I would set up web transforms: http://blogs.msdn.com/b/webdev/archive/2009/05/04/web-deployment-web-config-transformation.aspx ... and have a web.config for development and one for release. Solves the problem nicely. – Arran Sep 21 '12 at 14:12
  • If I use .net 3.5, is ot okay? –  Sep 21 '12 at 14:19
  • It's an IDE feature rather than Framework feature, so if you have Visual Studio 2010 or later you should be good. – Kynth Sep 21 '12 at 14:20

1 Answers1

1

This is quite a common approach and can work well.

Obviously you can run into problems if you get the details wrong while maintaining it by hand this way.

You could also have a look into web.config transformations: This is a way of writing a main web.config file and then writing separate files that change the original depending on the build configuration you run.

Some resources:

Community
  • 1
  • 1
Kynth
  • 2,597
  • 1
  • 18
  • 24