Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Password with special characters in connectionString

I need to connect to my Dynamics CRM 365 on premise instance from an ASP NET application. My problem is that the account for connection has a password like: T,jL4O&vc%t;30

  <connectionStrings>
    <add name="CRM365" connectionString="AuthType=AD;Url=http://crm.xxx.com/CRM365; Domain=test; Username=test; Password=T,jL4O&vc%t;30" />
  </connectionStrings>

I have the following error: vc is not defined

Please help. Thanks

like image 554
Oscar Dominguez Navarrete Avatar asked Apr 28 '20 17:04

Oscar Dominguez Navarrete


1 Answers

In this example I see two things:

  1. A & in xml should be escaped with &amp; (Good explanation in this answer)
  2. A ; in a connection string, you should wrap the password in single quotes

So this should work for you:

<connectionStrings>
    <add name="CRM365" connectionString="AuthType=AD;Url=http://crm.xxx.com/CRM365; Domain=test; Username=test; Password='T,jL4O&amp;vc%t;30'" />
</connectionStrings>

Edit (just tried it for myself):
Additionally, another variant is to use escaped double quotes:

<connectionStrings>
    <add name="CRM365" connectionString="AuthType=AD;Url=http://crm.xxx.com/CRM365; Domain=test; Username=test; Password=&quot;T,jL4O&amp;vc%t;30&quot;" />
</connectionStrings>

Summary:
Use either password='T,jL4O&amp;vc%t;30'; or password=&quot;T,jL4O&amp;vc%t;30&quot;;

like image 147
kapsiR Avatar answered Sep 20 '22 09:09

kapsiR