App. Config:
1 <?xml version= "1.0" encoding= "Utf-8"? >2 <configuration>3 <startup> 4 < Supportedruntime version= "v4.0" sku= ". netframework,version=v4.5 "/>5 </startup>6 <connectionstrings>7 <add name=" Dbconnstring "connectionstring=" Data source=.;i Nitial catalog=mytest123456; User Id=sa; password=123&456 "/>8 </connectionstrings>9 </configuration>
Because the password for the database connection contains the special character "&", the following error message appears at compile time:
Obviously the compiler does not know "&456", how to solve it, always can not change the password it?
In fact, App. Config is an XML file with special characters to be HTML escaped in an XML file.
<,>,& in HTML has special meanings (<,>, used for link-sign,& for escaping) and cannot be used directly. These symbols are not displayed in the pages we end up seeing, and if we want to display them in a Web page, we'll use the HTML escape string (Escape Sequence).
HTML Special escape Character list
Most commonly used character entities
Show Description Entity name Entity number
Spaces & #160;
< less than < & #60;
> Greater than > & #62;
& & Symbols & & #38;
"Double quotes " & #34;
© Copyright © & #169;
® Registered Trademarks ® & #174;
™ Trademark (United States) ™& #8482;
X Multiplication Sign × & #215;
÷ Division sign ÷ & #247;
So just escape the "&" and change the password to
password=123&456 "
Succeeded by compiling.
The writing method for special symbols in the config file in C #.