The SQL Server Data Tools team blog mentions that it is now possible to use MsBuild to perform a schema comparison of two DacPacs or databases. However, they do not mention exactly how to pass in the connection string to the source and target database. If I set the parameter /p:source="my connection string" I get the error:
MSBUILD : error MSB4177: Invalid property. The name "Initial Catalog" contains an invalid character " ".
The command-line my PowerShell script sends to msbuild is:
msbuild ".\SchemaCompare.proj" /t:SqlSchemaCompare
/p:source="$sourceConnString" /p:target="$targetConnString"
/p:XmlOutput="$schemaCompareReportPath"
where the SchemaCompare.proj contains the content suggested on the SQL Server Data Tools team blog
To compare database definitions. On the Tools menu, select SQL Server, and then click New Schema Comparison. Alternatively, right-click the TradeDev project in Solution Explorer, and select Schema Compare. The Schema Compare window opens, and Visual Studio automatically assigns it a name such as SqlSchemaCompare1 .
To connect to a database, the application provides a connection string which specifies parameters such as the host, the username, the password, etc. Connection strings have the form keyword1=value; keyword2=value; and are case-insensitive.
Right-click on your connection and select "Properties". You will get the Properties window for your connection. Find the "Connection String" property and select the "connection string". So now your connection string is in your hands; you can use it anywhere you want.
<connectionStrings> <add name="dbconnection" connectionString="Data Source=Soumalya;Integrated Security=true;Initial Catalog=MySampleDB" providerName="System. Data. SqlClient" />
It turns out that you have to replace the semicolons in the connection string with %3B
, like so:
$sourceConnString = $sourceConnString.Replace(";", "%3B")
Explanation: This prevents delimiter collisions between the SQL Server ConnectionString
value and the MSBuild /p
(a.k.a. /properties
) value that contains it. Absent this URL-encoding, MSBuild will tokenize the ConnectionString
on semicolons rather than passing on the whole value intact (for the SQL Server client libraries to tokenize). This also applies to the Properties
attribute of the MSBuild Task.
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With