The correct way to manage test / prod connection chains in the .NET web.config file

I have the source code of an application that I support. In my web.config file, I have connection strings for both test and production databases:

<add name="conn" connectionString="Data Source=TestDBServer; (etc...)">

<add name="conn" connectionString="Data Source=ProdDBServer; (etc...)">

Whenever I am in a test, I just comment out the production connection string and vice versa. For example, when I finish testing, I will comment out the test connection string and uncomment the production connection string, and then deploy.

I am very early in my development career, but it seems to me that there should be a better or more standard way to handle this. What should I do?

Edit

Guillerme Lofrano Corneto related an identical question that fully answers my own question. Since then I have been marked as a duplicate. Here's the link:

Change the connection string from development to release when publishing

+4
source share
3 answers

Visual Studio can automatically convert yours web.configbased on your active build configuration. Therefore, you must have the assembly configuration of "Test", "Dev", "Prod", etc. (What you need for your workflow).

web.config " ". web.Prod.config, . web.config .

, web.config, , "SlowCheetah - XML ​​Transforms"

+2

, - .

:

1- web.config. :

 <connectionStrings>
    <add name="ConnStringDb1"  connectionString="Data Source=TestDBServer; (etc...)" />
  </connectionStrings>

2- web.config web.release.config

enter image description here

3 Replace, , . xdt:Locator="Match(name)", (ConnStringDb1) :

<connectionStrings>
    <add name="ConnStringDb1"  xdt:Transform="Replace" xdt:Locator="Match(name)" 
         connectionString="Data Source=ProdDBServer; (etc...)" />
  </connectionStrings>

web.config.

+2
  • "dev" TFS . , SqlServer, , dev dev.

:   "\SqlServ2014Stand

- .

  1. For deployment in QA, Staging, UAT, Production (whatever you call them) ...... we write the wix installer (one per product) and process the xml transforms into a wix project. This is what the connection string (or something else) will change for different environments.

  2. You might want to look at a CI server, such as CruiseControl.NET or Jenkins or TFS. This is what will build your code sequentially. It takes a little time to configure. If time was the main factor, I would try Jenkins.

0
source

Source: https://habr.com/ru/post/1674475/


All Articles