Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a ConnectionString using Config Transformations

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...

like image 726
Didaxis Avatar asked Jan 19 '12 02:01

Didaxis


People also ask

How do you read connectionString from configuration file into code behind?

To read the connection string into your code, use the ConfigurationManager class. string connStr = ConfigurationManager. ConnectionStrings["myConnectionString"].

What is xdt transform replace?

A Transform attribute on a parent element can affect child elements even if no Transform is specified for them. For example, if you put the attribute xdt:Transform="Replace" in the system. web element, all the elements that are children of the system. web element are replaced with the content from the transform file.

How Web Config transform works?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

What is connectionString in web config?

<connectionStrings> <add name="dbconnection" connectionString="Data Source=Soumalya;Integrated Security=true;Initial Catalog=MySampleDB" providerName="System. Data. SqlClient" />


1 Answers

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.

like image 133
hyke20 Avatar answered Sep 17 '22 02:09

hyke20