I have an ASP.NET web application project that connects to a remote database through the Entity Framework. During debugging (for example, when starting a project on my local computer), the IP address in the database is different from when it was released (for example, after loading a project on my web server and launching it from a browser). Until now, I have always manually changed the database connection string in the Web.config file to switch between the two (basically I had to use connection strings, one with the name “Debug” and one with “Release”), and I just exchanged names when every deployment).
Now, I just noticed that you can let this happen automatically using the Web.config conversion syntax, where you put the changed connection string in the version of Web.Release.config, and it should then use it when building the DLL in the release configuration.
However, this does not seem to work for me ...
Here is the relevant part of my regular Web.config file (which contains the Debug connection string for local use):
<?xml version="1.0"?> <configuration> <connectionStrings> <add name="DatabaseEntities" connectionString="A" providerName="System.Data.EntityClient" /> </connectionStrings> </configuration>
Here is the Web.Release.config file, which, according to the examples, should replace the connection string "DatabaseEntities" "A" with "B" if the DLL is in Release mode:
<?xml version="1.0"?> <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <connectionStrings> <add name="DatabaseEntities" connectionString="B" xdt:Transform="Replace" xdt:Locator="Match(name)"/> </connectionStrings> </configuration>
(Obviously, “A” and “B” are just placeholders for my real join strings)
When I debug the application (for example, just press F5), the default is Web.config and I can access the database. Then I change the build configuration to Release through Configuration Manager. All projects in the solution are configured to release the configuration. Then I build the solution (simply through Build or even through a complete rebuild (e.g. Clean, Rebuild)). I upload the newly created DLLs to the web server, as well as the Web.config and Web.Release.config files, and when I try to access the database, I cannot, it is still trying to access the database via IP debug address. and therefore cannot find it ...
The Web.Release.config file seems to be completely ignored, or at least the connection string is not replaced.
What am I doing wrong? Is the conversion syntax incorrect? Am I not correctly building the application in Release mode?