locked
Removing specific connection strings in web.config transformation RRS feed

  • Question

  • User-2145974911 posted

    I have a few connection strings in my web.config that I want to remove using web.config transformation when I deploy my web app. I had found the MSDN page talking about web.config transformation but it only list a "Remove" which removes the first entry or the "RemoveAll" that deletes them all. Is there a way to only remove specific connection strings?

    <connectionStrings>
        <add name="DB"
             connectionString="Data Source=; Initial Catalog=; User ID=; Password=;"
             providerName="System.Data.SqlClient" />
        <add name="ErrorLog"
             connectionString="Data Source=; Initial Catalog=; User ID=; Password=;"
             providerName="System.Data.SqlClient" />
        <add name="SiteFiles"
             connectionString="" />
        <add name="FanFiles"
             connectionString="" />
      </connectionStrings>
    Sunday, May 26, 2013 5:08 PM

Answers

  • User-2009179499 posted

    If the "remove" is removing the first entry, you must not have specified a locator.  You need an "xdt:locator" to tell the transform engine which entry you're talking about.  There are several examples in the page quoted above, but under different verbs (check the Match command).

    This locator finds the key specified, then the transform verb says to remove the node.

    <add key="myKeyToRemove" value="UnimportantValue" xdt:Transform="Remove" xdt:Locator="Match(key)"/>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 3, 2013 2:15 PM

All replies

  • User-1716253493 posted
    Transform="Remove"

    http://msdn.microsoft.com/en-us/library/dd465326.aspx

    Sunday, May 26, 2013 8:26 PM
  • User-2145974911 posted

     

    As stated in my original post:

    I had found the MSDN page talking about web.config transformation but it only list a "Remove" which removes the first entry or the "RemoveAll" that deletes them all. Is there a way to only remove specific connection strings?

     

    That artical I talk about is the exact one you pointed me to which, as I said, only tells you how to remove them all or only remove the first entry. I need to be able to specifiy which entries to remove.

    Sunday, May 26, 2013 8:33 PM
  • User-2009179499 posted

    If the "remove" is removing the first entry, you must not have specified a locator.  You need an "xdt:locator" to tell the transform engine which entry you're talking about.  There are several examples in the page quoted above, but under different verbs (check the Match command).

    This locator finds the key specified, then the transform verb says to remove the node.

    <add key="myKeyToRemove" value="UnimportantValue" xdt:Transform="Remove" xdt:Locator="Match(key)"/>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 3, 2013 2:15 PM