How to include ampersand in connection string? How to include ampersand in connection string? asp.net asp.net

How to include ampersand in connection string?


You'll need to use escape sequences like you would for any XML document, which is all the .config files are.

  • Ampersand = & = &
  • Greater Than = > = >
  • Less Than = < = <
  • Apostrophe = ' = &apos;
  • Quote = " = "

You can also use the CDATA tag so that you can use these illegal characters

<![CDATA[ and ends with ]]>

<connectionStrings>    <add name="MyEntities" connectionString="        metadata=res://*/MyDataModel.csdl|res://*/MyDataModel.ssdl|res://*/MyDataModel.msl;        provider=System.Data.SqlClient;        provider connection string="        Data Source=localhost\DEV;        Initial Catalog=MyDB;UserId=myUser;        Password=<![CDATA[jack&jill]]>;        MultipleActiveResultSets=True""         providerName="System.Data.EntityClient" /></connectionStrings>