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="Data Source=localhost;Initial Catalog=Northwind;Persist Security Info=True;User Id=foo;password=bar;Enlist=False;"" />
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="Data Source=localhost%3BInitial Catalog=Northwind%3BPersist Security Info=True%3BUser Id=foo%3Bpassword=bar%3BEnlist=False%3B"" />
Hope this helps! You can also escape the spaces with   but I don’t believe that’s required.