Reputation: 45490
I can see that Web.config
file contains two files:
-web.Debug.config
-web.Release.config
Inside this config files there is the following comment:
In the example below, the "SetAttributes" transform will change the value of "connectionString" to use "ReleaseSQLServer" only when the "Match" locator finds an atrribute "name" that has a value of "MyDB".
<connectionStrings>
<add name="MyDB"
connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
What is the "Match" locator
?
I already have a connection String in Web.config
So how do I set this up?
should the main web.config file contain the production connection string or the other way around?
I'm looking for adivices from people that have done similar things
Upvotes: 4
Views: 5183
Reputation: 9854
Match(name)
means that the name of the connectionString
in your case MyDB if it is same as in web.config that it will set the connectionString
attributes to what you have in your web.debug.config
file's connectionString
when you publish the website. A complete documentation can be found at MSDN. And a basic how to do can be found here.
Upvotes: 0
Reputation: 2843
We are using xdt:Transform="Replace" which basically replaces the connection string of our development DB and it works perfectly. See below:
Development connection string (in your case web.Debug.config):
<connectionStrings>
<add name="MyDB" connectionString="Data Source=DebugSQLServer;Initial Catalog=MyDebugDB;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
Production connection string (in your case web.Release.config):
<connectionStrings xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<add name="MyDB" connectionString="Data Source=ReleaseSQLServer;Initial Catalog=MyReleaseDB;Integrated Security=True" xdt:Transform="Replace" xdt:Locator="Match(name)" />
</connectionStrings>
Upvotes: 7