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

Glossary Item Box


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

 

To compare and synchronize the schema:

  1. Create two Database objects.

    You can register them from online databases or by loading them from SQL Compare snapshots previously saved to disk.

  2. Compare the two databases using the CompareWith method. 
  3. Take the resulting Differences object, create a Work object, and call BuildFromDifferences.

    All objects in the Differences collection are selected for synchronization by default. However, you should explicitly set the Selected property to true for the objects that you want to synchronize, or false for those objects that you do not want to synchronize. This will ensure the correct objects are included when you build the synchronization script.  

    You can then access Messages and Warnings to see information about the comparison.

  4. 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.

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

 

Note that if you are synchronizing to a scripts folder, the procedure is different. See  Frequently Asked Questions for the SQL Compare API.

 

For a detailed example, see Worked Example.

 

See Also

Getting Started with the SQL Compare API

Distributing Your Applications