MSBuild Invalid Character in Connection String with dbproj

If you get this error:

error MSB5016: The name “Intitial Catalog” contains an invalid character “ “.

or something similar when trying to specify a connection string within an MSBuild task, like this one:

<MSBuild Projects="src\Databases\Northwind.dbproj" 
    Targets="Build;Deploy" 
    Properties="TargetDatabase=Northwind;TargetConnectionString=&quot;Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=True;User Id=foo;password=bar;Enlist=False;&quot;" />
 
 

The issue is with the semicolons in the querystring.  If you replace them with %3B then the error goes away:

<MSBuild Projects="src\Databases\Northwind.dbproj" 
    Targets="Build;Deploy" 
    Properties="TargetDatabase=Northwind;TargetConnectionString=&quot;Data&#x20;Source=localhost%3BInitial&#x20;Catalog=Northwind%3BPersist&#x20;Security&#x20;Info=True%3BUser&#x20;Id=foo%3Bpassword=bar%3BEnlist=False%3B&quot;" />
 
 

Hope this helps!  You can also escape the spaces with &#x20; but I don’t believe that’s required.

blog comments powered by Disqus