Prevent Percent Character Transform
Asked Answered
C

2

10

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>
Cosmogony answered 28/6, 2011 at 15:30 Comment(6)
Try using %% to escape the percent sign?Pachton
@Jacob - That gets it closer. I put in "pwd=abc123%%72" and am getting "pwd=abc123%r" out after the transform.Cosmogony
How about this: pwd=abc123%%372Pachton
@Jacob - Still no go, now it outputs pwd=abc123rCosmogony
serverfault.com/questions/212687/… seems to have the same problem, but no answerPachton
Hi Adam, can you explain the steps you are taking and where it is failing? I cannot piece it together based on your question so its difficult to give a recommendation here.Armed
V
13

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.

Volt answered 30/3, 2012 at 20:42 Comment(4)
This solution worked perfectly for me. I don't know if it is a bug or just undocumented operation of the parser but if someone has a better explanation I would be interested in it as well. Thanks for finally coming up with a solution to the issue. I had since "resolved" the issue by using the Parameters.xml file and making the connection string as a parameter, but I would have preferred to use the built in web/app.config functionality of specifying based on build type (Debug/Release/Production/Test, etc).Cosmogony
You are welcome. I wonder if this can be posted somewhere on MS site to get more attention. Glad I was able to answer, even if it was too late.Volt
@Volt : This is reported yet a few years ago. see here and the bug is still there. Replacing % with %25 just once helped for me.Skipp
@Skipp If you were able to get it to work by only using %25 then the issue seems to have been fixed. Back when I had this problem, we had to use %2525.Volt
C
0

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.

Consolidation answered 27/8, 2014 at 9:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.