Question

I have a Web.config file and a Web.Debug.Config file. My Web.Debug.Config file is practically empty and I would like to add to it a connectionstrings section to override the one in the Web.Config file. I tried just adding the connectionstrings section in the config file but it didn't pick it up. I know there are some commands I need to use in one or both config files but am not sure what they are. Can someone help me out please?

Thanks,

Sachin

Was it helpful?

Solution

You should be able to do the following (not tested, but should work) to replace the Web.Config file's connectionStrings section:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings xdt:Transform="Replace">
    <add name="AuthenticationDatabase" connectionString="connection-string-here" providerName="System.Data.SqlClient" />
    <add name="OtherDatabase" connectionString="connection-string-here" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

If you're just looking to update an existing connectionString:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <connectionStrings>
    <add xdt:Transform="SetAttributes" xdt:Locator="Match(name)" name="AuthenticationDatabase" connectionString="new-string-here" providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top