The SQL Data Compare API Submit feedback on this topic   
Comparing and Synchronizing Data Using the API

Glossary Item Box


To automate the comparison and synchronization of database data, you use the SQL Data Compare API. You must reference the following assemblies from your Visual Studio .NET project:

 

To compare and synchronize the data:

  1. Create a SqlCompare.Database object and call RegisterForDataCompare with a SqlCompare.ConnectionProperties object.
  2. Set up a SchemaMappings or TableMappings collection containing information about which tables, views, fields, and keys are to be used in the comparison.

    The easiest way to do this is to call CreateMappings on the SchemaMappings or TableMappings object. 

  3. Create a ComparisonSession object and call CompareDatabases.
  4. Use the TableDifferences property to view the differences in data between the two databases.
  5. Create a SqlProvider object and call the GetMigrationSQL method to retrieve an ExecutionBlock object containing the synchronization SQL code.
  6. To run the synchronization script, create a BlockExecutor object and call ExecuteBlock, passing in the ExecutionBlock object.

    You can receive feedback events about the progress of the comparison and synchronization by using the ICancellable interface.

  7. Dispose of the objects when you have finished using them.

 

For a detailed example, see Worked Example.

 

See Also

Getting Started with the SQL Data Compare API

Distributing Your Applications