Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
337 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...