MSBuild Invalid Character in Connection String with dbproj
Date Published: 03 February 2011
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=<span style="color: #006080">"srcDatabasesNorthwind.dbproj"</span>
Targets=<span style="color: #006080">"Build;Deploy"</span>
Properties=<span style="color: #006080">"TargetDatabase=Northwind;TargetConnectionString="Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=True;User Id=foo;password=bar;Enlist=False;""</span> />
 
 
The issue is with the semicolons in the querystring. If you replace them with %3B then the error goes away:
<MSBuild Projects=<span style="color: #006080">"srcDatabasesNorthwind.dbproj"</span>
Targets=<span style="color: #006080">"Build;Deploy"</span>
Properties=<span style="color: #006080">"TargetDatabase=Northwind;TargetConnectionString="Data Source=localhost%3BInitial Catalog=Northwind%3BPersist Security Info=True%3BUser Id=foo%3Bpassword=bar%3BEnlist=False%3B""</span> />
 
 
Hope this helps! You can also escape the spaces with but I don’t believe that’s required.
Tags - Browse all tags
Category - Browse all categories
About Ardalis
Software Architect
Steve is an experienced software architect and trainer, focusing on code quality and Domain-Driven Design with .NET.