Different connectionstring for different builds

Asked

Viewed 189 times

8

I have two Connection string, one when I am in development that uses my local bank and the other for when I deploy the application in Azure.

I want the app to know which one to use depending on the build type I do. What’s the simplest way to do this?

From to do at the level of string Connection or I would need two different Web.config?

  • 1

    See if this helps you: http://blogs.msdn.com/b/webdev/archive/2009/05/04/web-deployment-web-config-transformation.aspx https://msdn.microsoft.com/en-us/library/vstudio/dd465318(v=vs.110). aspx

1 answer

8


The procedure is very similar to this answer here, only that for <connectionstrings>. For example:

Web.Release.config

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <connectionStrings>
      <add name="DefaultConnection"
        connectionString="MinhaConnectionStringDeProdução"
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
</configuration>

Web.Debug.config

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <connectionStrings>
      <add name="DefaultConnection"
        connectionString="MinhaConnectionStringDeDebug"
        xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
    </connectionStrings>
</configuration>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.