Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ConnectionStrings in app.config with characters that the .config file doesn't like

I've looked for the answer and can't find it. It's got to be something obvious and I'm just missing it.

We have a connection string issue in an app.config file. It uses SQL Server authentication, and the password contains an "&" and a "+" symbol. Obviously the parsing is going wrong. Changing the password would be a hassle at this point. Is there a way to handle this?

partial connection string with sensitive data blocked

like image 434
David Avatar asked Apr 13 '12 13:04

David


4 Answers

Encode the '&' as '&' - ampersand is a reserved character in XML

More info: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

like image 157
DaveRead Avatar answered Nov 18 '22 08:11

DaveRead


Since the web.config is XML, you need to escape the five special characters:

& -> & ampersand, U+0026
&lt; --> < left angle bracket, less-than sign, U+003C
&gt; --> > right angle bracket, greater-than sign, U+003E
&quot;-> " quotation mark, U+0022
&apos;-> ' apostrophe, U+0027

+ is not a problem, I suppose.

like image 38
Emanuele Greco Avatar answered Nov 18 '22 08:11

Emanuele Greco


web.config is an XML file and XML content needs to be escaped...

Change the & to &amp; in the password field and you are good to do.

like image 32
Oded Avatar answered Nov 18 '22 07:11

Oded


Try encoding the characters. Use &amp; for ampersand.

like image 28
WhistlingZebra Avatar answered Nov 18 '22 08:11

WhistlingZebra