1
votes

I've got a web.config that contains my SQL connection string and my Azure Blob storage connection string.

A Web.Config transformation replaces my Local SQL connection string with the Azure one.

When I publish the site to Azure, the Blob storage connection string is deleted and replaced with a duplicate SQL connection string, but with the blob storage string's name.

The only way I've found to fix is to log in via FTP and manually change the erroneous Storage connection string with the correct one from my local machine.

How do I get VS to publish my web config to Azure and leave it alone!!!

Web.Config

      <connectionStrings>
    <add name="DefaultConnection" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="StorageConnectionString" connectionString="DefaultEndpointsProtocol=https;AccountName=;AccountKey=" />
  </connectionStrings>

Web.Release.Config

  <connectionStrings>
<add name="DefaultConnection"
     connectionString="Server=.database.windows.net,1433;Database=;User ID=@;Password=!;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
     providerName="System.Data.SqlClient"
     xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
2
There could be some config transformation defined that may be doing it. Do you have files such as web.release.config, web.debug.config. Check these files.Chandermani
I've got Web.Release.Config and Web.Debug.Config. The Release.Config is configured to change the SQL string to the live server. That's all. It shouldn't be altering the Blob storage connection. I'll test the transformations locally to be sure.Ben Ford
Share your source web.config and the web transform you're using and the publish build configuration. In VS 2012+ - You can right click a transform and select "Preview Transform" to see the output. This is what will be pushed to Azure - assuming you are using VS.NET to deploy. What is your deployment/packaging method?SliverNinja - MSFT

2 Answers

1
votes

I had a similar issue to yours. I'm not sure why but when you define the connection strings in the "Configure tab" in the azure portal and associate a "Linked Resource" on the linked resource tab it may override certain properties in the Web.config transform causing unexpected results. One of the options when you set up a new azure website is linking to (or creating a new) database to associate with your website - thereby automatically assigning the related connection string which may try to override your transform operation defined in the Web.Release.config.

Check and see if removing all connection strings and linked resources inside the "Azure Portal" fixes your problem. Just make sure that you have both your production database and storage connections strings defined properly in the Web.Release.config.

1
votes

I struggled with this problem this morning and I came up with a solution for VS2015/17.

So I have an Azure VM, and to publish my web app on this machine, I used the Web deploy to an Azure VM proposed by VS.

I put my connection strings in an external file, so the useful part of my web.config looks like this :

  </entityFramework>
  <connectionStrings configSource="ConnectionStrings.config">
  </connectionStrings>
</configuration>

in order to prevent VS of adding some connection strings during publication (ADO.Net code first MSSQL database connection string in my case), you can edit the following file in your project :

...\MyProject\Properties\PublishProfiles\YourPublishProfile - WebDeploy.pubxml

In this file look into the ItemGroup part and edit it to delete the connection strings you don't need:

<PublishDatabaseSettings>
  <Objects xmlns="">
    <ObjectGroup Name="MyProject.Models.MSSQL_DB" Order="1" Enabled="False">
      <Destination Path="" />
      <Object Type="DbCodeFirst">
        <Source Path="DBContext" DbContext="MyProject.Models.MSSQL_DB, MyProject" Origin="Convention" />
      </Object>
    </ObjectGroup>
  </Objects>
</PublishDatabaseSettings>
</PropertyGroup>
<ItemGroup>
    <here are some entries delete the ones you don't need/>
</ItemGroup>

Be careful, if you add a file in this repertory, there is chances that it breaks the publication process on VS. Don't add file, just edit.