Nice programing

구성 변환을 사용하여 ConnectionString을 제거하는 방법

nicepro 2020. 11. 16. 22:10
반응형

구성 변환을 사용하여 ConnectionString을 제거하는 방법


여러 ConnectionStrings가있는 Web.config가 있습니다.

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

구성 변환을 사용하여 특정 연결 문자열을 제거하는 방법이 있습니까? 같은 것 :

<connectionStrings>
    <xdt:Remove connStr2?

분명히 정확한 구문 근처에는 없지만 내 드리프트가 있습니다 ...


주제에 대한 MSDN 문서 에서 :

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add xdt:Transform="Remove" />
  </connectionStrings>
</configuration>

Transform="Remove"당신이 찾고있는 마법이다. 또한이 Transform="RemoveAll"특정 추가 기능 (들)와 함께 사용할 수 있습니다있다.

편집하다

제 생각에 당신은 또한 결합 할 수 있습니다 Locator속성을Remove당신이 실제로 삭제할 요소 한계 이상으로 정의했다.

보다 명확하게 :

<configuration xmlns:xdt="...">
  <connectionStrings>
    <add xdt:Transform="Remove" xdt:Locator="XPath(configuration/connectionStrings[@name='ConnStr2'])" />
  </connectionStrings>
</configuration>

또는 유사하게 작동합니다.


이름에 따라 특정 연결 문자열이 제거됩니다.

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

점을 유의 connectionString값이 빈 문자열이 아니라 대신 공간입니다. 비어 있지 않은 값은 가능합니다.

참고 URL : https://stackoverflow.com/questions/8920451/how-to-remove-a-connectionstring-using-config-transformations

반응형