Reputation: 2674
I am attempting to use the Web Deployment Toolkit with our MVC3 project and overall the deployment works fine but our connection string to the database has a password that contains a percent (%) character that is followed by two numbers. The deployment toolkit seems to be transforming this as a Hex character replacement. Is there a way to prevent this character replacement and still keep the connection string usable on developer machines? I tried putting in the replacement in the Web.Debug.Config file and even adding a %25 instead of just the % to try to have it replace just the % character and it still replaces the complete value.
Example:
<connectionStrings>
<add name="MyDB" connectionString="server=Server1;uid=user1;pwd=abc123%72;database=Database1;"
</connectionStrings>
gets replaced with
<connectionStrings>
<add name="MyDB" connectionString="server=Server1;uid=user1;pwd=abc123r;database=Database1;"
</connectionStrings>
Upvotes: 10
Views: 1964
Reputation: 1
I've run into the exact same issue (with a different password of course).
To keep the connection string to the database working on the developer machines i've modified the publish settings to use a 'different' connections string.
For your example: web.config would contain:
<connectionStrings>
<add name="MyDB" connectionString="server=Server1;uid=user1;pwd=abc123%72;database=Database1;"
</connectionStrings>
Under the publish settings right-click project, select publish..., go to settings->databases. For the database MyDB, enter
server=Server1;uid=user1;pwd=abc123%72;database=Database1;
This allowed my developer machine to retain it's connection to the database and the host machine to automatically use the correct connection string both by publishing directly or through teamcity.
Upvotes: 0
Reputation: 10730
Set the pwd portion of the connection string to:
pwd=abc123%252572
After much trial and error, I discovered that It does a double pass. The first pass will convert %2525 to %25, the second pass converts %25 to %. That is why when you used %2572, it resulted in r (%72 is the Unicode code for r). This seems to me like a bug in the parser. Perhaps someone more knowledgeable can give a better explanation.
Upvotes: 13