1

I have this in my Web.config so that my service will run locally:

  <connectionStrings>

    <add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=IPADD;Initial Catalog=DB;Persist Security Info=True;User ID=UN;Password=PW" />
  </connectionStrings>

I need this here because the Web.Debug.Config doesn't work. So when I publish I want to remove this string because it is actually inherited from a parent Web.config

  <connectionStrings>
    <remove name="DefaultConnection"/>

  </connectionStrings>

This doesn't seem to work... (it throws a The entry 'DefaultConnection' has already been added. error)

How can I remove it? XSLT?

P.s. I can't use clear/ because it removes the Machine.Config DB Connection string to the Membership provider also throwing a different error

1 Answer 1

6

Put below code:

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

But be careful when you do publish from visual studio. When you look on Output view. It should write you something like:

Transformed Web.config using Web.Release.config into obj\Debug\TransformWebConfig\transformed\Web.config.
Copying all files to temporary location below for package/publish:

But if you have active "Debug" you will have Web.Debug.config instead of Web.Release.config

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

Comments

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.