Wednesday, December 12, 2007

Automatically Compare Data and Schema Using MSBuild and Data Dude

VSTS for DB Professionals (aka "Data Dude" or "VSDBPro") provides great tools for schema and data compare.

Like most Visual Studio-based project systems, the core tasks inside the VSDBPro project implemented as MSBuild tasks. The two core activities for Database Projects (.dbproj), “Build” and “Deploy” are implemented by two MSBuild tasks named “SqlBuildTask” and “SqlDeployTask.”

Sometimes, we also need to automate the schema and data compare processes. We can do it with new MSBuild dedicated tasks that shipped with Power Tools for Data Dude:(Currently available for VSTS 2005)

  • SqlDataCompareTask: allows you to compare the content of tables within two databases from the command line using MSBuild
  • SqlSchemaCompareTask: allows you to compare schemas between two database from the command line using MSBuild

How should you use it?

First, install the Power Tools. Download from here. (notice that the power tools requires Data Dude Service Release 1 installed).

After you installed the power tools you can use the tasks in your MSBuild script.


  <!--Import the settings-->
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0

<Target Name ="DataCompare">
SourceConnectionString="Data Source=(.);Integrated Security=True;Pooling=False"
TargetConnectionString="Data Source=(.);Integrated Security=True;Pooling=False"
OutputPath = "$(temp)"
OutputFileName = "DataCompare.sql"/>

Notice that the task does not allow you to compare against the project right now. Same way you can use the SqlSchemaCompareTask.

<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v8.0
<Target Name ="SchemaCompare">
OutputPath = "$(IntermediateOutputPath)"
OutputFileName = "$(TargetDatabase)SchemaCompare.sql"
IgnoreChecks ="true"

The properties exposed by the MSBuild tasks are documented via an accompanying XSD file located in:

%ProgramFiles%\Microsoft Visual Studio 

No comments: