0

I have never used transformations before. I a trying to use two different connection strings with my ASP.NET MVC 5 project.

Here is a summary of my Web.config file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <!-- more -->

  <connectionStrings>
    <add name="ChopsticksDBContext" providerName="System.Data.SqlClient" connectionString="Data Source=tcp:s10.winhost.com;Initial Catalog=DB_XXX31_kieXXX;User ID=DB_XXX31_kieXXX_user;Password=XXXX;Integrated Security=False;" />
  </connectionStrings>
</configuration>

And I added the following tags into my Web.Debug.config file:

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

  <!-- more -->

  <connectionStrings>
    <add name="ChopsticksDBContext"
      providerName="System.Data.SqlClient"
      connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-KiewicWebsite-20131214161254;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-KiewicWebsite-20131214161254.mdf"
      xdt:Transform="Replace" xdt:Locator="Match(name)"/>
  </connectionStrings>
</configuration>

I am running my porject in Debug mode and I am still getting the original value for the connection string.

Any idea what could be wrong?

1
  • I learned that concept is that you need connection string from web.config when you are developing on your local machine, later you deploy it on some dev/debug machine, in this case when you publish to dev machine transform will work an update config accordingly, logically you need to add more configurations to solution like staging, test etc. Commented May 21, 2020 at 21:27

2 Answers 2

7

The problem is that transformations are not applied when running your application in Debug mode. Transformations are only applied when you do a Publish of your website. You can verify this by doing a Publish using the Debug configuration. The published site will have the transformation applied, which in your case means that the connection string has been replaced.

Sign up to request clarification or add additional context in comments.

3 Comments

Since I usually publish the Release configuration, it makes more sense to move the transformation to Web.Release.config. Thank you.
This is no longer true. JetBrains Rider 2022.1.1 transforms on build.
It's as true as ever. Not everyone uses that third-party tool!
4

The transformations does only have effect when you publish your project. (Use the "publish" feature in Visual Studio).

When you run your app locally, it will use the connectionstring in the web.config

1 Comment

What is the point of Web.Debug.config then? Is someone supposed to publish a Debug configuration?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.