0

in my web.config

<connectionStrings>

    <add name="Context" connectionString="Server=tcp:database.windows.net,1433;Database=DbDev;User ID=xxxx;Password=xxxx.;Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True"
    providerName="System.Data.SqlClient" />
<connectionStrings/>

my web.Debug.config

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

    <connectionStrings>

      <add name="Context" connectionString="Server=tcp:database.windows.net;Database=DbDev;
      User ID=xxxx;Password=xxxx.;
      Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True"
    providerName="System.Data.SqlClient" xdt:Transform="Replace" xdt:Locator="Match(name)"/>
    </connectionStrings>

  <system.web>

      <customErrors mode="Off" xdt:Transform="Replace">

      </customErrors>

    </system.web>
</configuration>

in my web.Release.config

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">

    <connectionStrings>

      <add name="Context" connectionString="Server=tcp:database.windows.net;
           Database=DbProd;User ID=xxxx;Password=xxxx.;
           Trusted_Connection=False;Encrypt=True;MultipleActiveResultSets=True"
            providerName="System.Data.SqlClient" 
            xdt:Transform="Replace" xdt:Locator="Match(name)" />
    </connectionStrings>

    <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />

      <customErrors defaultRedirect="GenericError.htm" mode="On" xdt:Transform="Replace">
        <error statusCode="500" redirect="InternalError.htm"/>
      </customErrors>

    </system.web>
</configuration>

it's just not getting the production database DbProd

Kiddo
  • 5,052
  • 6
  • 47
  • 69

2 Answers2

3

i think when running 'release' mode in VS, it will transform the web.release.config file, but it won't use it due to some reasons ( cache? bin?).However, when I publish it in the Azure environment, then it will get the config correctly

Kiddo
  • 5,052
  • 6
  • 47
  • 69
  • Same for me. Switched to "Release" locally and it didn't switch out my connection strings, but once I published to Azure it worked. – Justin Jan 06 '13 at 23:39
  • Also you can read this and will understand that this transform works only when publish https://stackoverflow.com/questions/14415614/web-config-build-vs-release-transform-not-working – mihkov Sep 08 '17 at 10:59
1

xdt:Locator="Match(name)" means transformed values will be applied if name attribute values match.

In web.config you have

<add name="Context"

But in web.release.config

<add name="PoqContext" 

Changing connection string names to same value should help you. Also, take a look at Web.config Transformation Syntax for other available options

archil
  • 39,013
  • 7
  • 65
  • 82