Connectionstring according to scenario

1

Hello, good morning!

I have a project where there are two scenarios, which is homologation and production. In this same project I created two connectionstrings , setting one for each scenario.

In the system these scenarios are divided into subdomains, such as homolog.domain.com and the domain.com itself.

Now comes the question: Is there a way to create a setting for connectionstring to fit the scenario? When I access the homolog it automatically picks up the% of the homologation.

You're like this:

<connectionStrings>
    <add name="connectionstring_homolog" providerName="System.Data.SqlClient" connectionString="Data Source=xxxx;Initial Catalog=xxxxxx; User ID=xxxxxx; pwd=xxxxxxx;" />
    <add name="connectionstring_prod" providerName="System.Data.SqlClient" connectionString="Data Source=xxxxxx;Initial Catalog=xxxxxx; User ID=xxxx; pwd=xxxxx;" />
  </connectionStrings>

Remembering that I'm using ASP.Net MVC.

Thank you in advance.

    
asked by anonymous 26.02.2016 / 13:42

1 answer

2

First you should look inside your application in Web.Config

In the web.config session put the following code:

  <connectionStrings configSource="WebConnStrDevelopment.config">
    <!-- @configSource será modificado na publicação. Ver Web.Release.config -->
  </connectionStrings>

Now in your Web.Release.config add the following code:

 <connectionStrings configSource="WebConnStrProduction.config" xdt:Transform="SetAttributes(configSource)" />

Now add 2 new config files called (WebConnStrDevelopment and WebConnStrProduction)

Within the WebConnStrDevelopment.config file add the following code:

    <connectionStrings>
    <add name="connectionstring"  //adicionar conexão de dev />
  </connectionStrings>

Within the WebConnStrProduction.config file add the following code:

      <connectionStrings>
    <add name="connectionstring"  //adicionar conexão de prod/>
  </connectionStrings>

You can read more here at the MSDN

    
26.02.2016 / 14:09