Data Compare DTE Commands

In this blog I’ll lead you through the various parameters for the “Data.NewDataComparison” command available in the General Distribution Release (GDR) for Visual Studio Team System 2008 Database Edition. This command launches the Visual Studio Data Compare editor.

If you have the Visual Studio Team System 2008 GDR installed, open it and navigate to the Command Window. To display the Command Window, open the View menu, point to Other Windows, and click Command Window. At the prompt type “Data.NewDataComparison”. The New Data Comparison dialog will appear. This is the expected result when executing “Data.NewDataComparison” without parameters. To avoid this dialog and immediately produce a data comparison result the following parameters are available:

Data.NewDataComparison /SrcServerName srcServer /SrcDatabaseName srcDatabaseName /SrcDisplayName displayName [/SrcUserName username] [/SrcPassword password] /TargetServerName targetServer /TargetDatabaseName targetDatabaseName /TargetDisplayName displayName [/TargetUserName username] [/TargetPassword password]

The command will have the general form is “Data.NewDataComparison <source options> <target options>”

/SrcServerName

/TargetServerName

Specify the name of the server that contains the data for the source/target of the comparison.

/SrcDatabaseName

/TargetDatabaseName

Specify the name of the database that contains the data for the source/target of the comparison.

/SrcDisplayName

/TargetDisplayName

Specify the name that you want to appear in the Schema Compare window for the source/target of the comparison.

/SrcUserName

/TargetUserName

Specify the user name that you want to use to connect to the database that contains the data for the source/target of the comparison.

If you’re using windows authentication you can ignore this option.

/SrcPassword

/TargetPassword

Specify the password for the user name that you want to use to connect to the database that contains the data for the source/target of the comparison. 

If you’re using windows authentication you can ignore this option.

I have two named SQL Server 2008 instances on my box – SQL2008_1 and SQL2008_2. The first instance has a database named ‘Drake’ and the other ‘Josh’. I’m using windows authentication, so no username or password is required.  A Data Compare session can be launched by typing the following command into the Command Window

Data.NewDataComparison /SrcServerName .\SQL2008_1 /SrcDatabaseName Drake /SrcDisplayName Drake /TargetServerName .\SQL2008_2 /TargetDatabaseName Josh /TargetDisplayName Josh

If differences are available, I can now use the command “Data.DataCompareExportToFile [filename]” to create a data update script. When I execute “Data.DataCompareExportToFile C:\JoshUpgrade.sql" in the Command Window a data upgrade script will be created.

Conclusion

At this point I’ve illustrated how to use the Import Script, Schema Compare and Data Compare DTE commands. I hope you’re starting to see the flexibility this provides for authoring your own addins, packages or applications tailored to your specific requirements.

- Patrick Sirr

“DataDude” Programmer