How to remove a ConnectionString using Config Transformations

Didaxis picture Didaxis · Jan 19, 2012 · Viewed 47.8k times · Source

I have a Web.config with several ConnectionStrings

<connectionStrings>
    <add name="connStr1" connectionString="...
    <add name="ConnStr2" connectionString="...
    <add name="connStr3" connectionString="...

Is there a way using config transformations to remove a specific connectionstring? Something Like:

<connectionStrings>
    <xdt:Remove connStr2?

Obviously no where near the correct syntax, but you get my drift...

Answer

hyke20 picture hyke20 · Jan 30, 2012

This will remove a specific connection string based on its name.

<configuration>
  <connectionStrings> 
    <add name="ConnStr2" xdt:Transform="Remove" xdt:Locator="Match(name)" connectionString=" " /> 
  </connectionStrings> 
</configuration>

Note that the connectionString value is not empty string, but is instead a space. Any non-empty value would do.