The SQL Compare API Submit feedback on this topic   
Frequently Asked Questions for the SQL Compare API

Glossary Item Box


How do I access the SQL Data Definition Language script for an object?

Register the database, then create a Work object. Use the ScriptObject method of Work to return a Regions object. This contains a collection of the individual lines of SQL code (regions) used to create the object.


How do I use the API to set the comparison options?

The CompareWith method of the Database object accepts an enumeration of options as the final argument. For a list of the options, see Options Enumeration. To use more than one option, logically OR them together:

enOptions = IgnoreFillFactor Or IgnorePermissions

Options enOptions = Options.IgnoreFillFactor | Options.IgnorePermissions

By default, the following options are set:


How do I include objects in, or exclude objects from, the synchronization?

The CompareWith method of the Database object returns a Differences collection. When you call the BuildFromDifferences method of the Work object to generate the synchronization SQL script, it includes only the differences from the Differences collection that are set to true. By default, all differences are set to true, and therefore included. You should explicitly set the Selected property to true for the difference objects that you want to include in the synchronization, or false to exclude a difference object.


How do I export a schema to a scripts folder?

You can save a schema to a specified folder as a collection of object creation scripts. Create a WriteToFileOptions object. Call SaveToFolder in a Database object, passing in the name of an empty folder. Note that SQL Compare will overwrite anything in the folder if it is not empty.


How do I synchronize to a scripts folder?

  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 with a WriteToFileOptions object.

    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. Call Check on ScriptSynchronizationActions in the Work object. If no exceptions occur, call Execute on the same object.

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

 

How do I generate a report?

You can generate reports using the graphical user interface supplied with the SQL Compare program. Unfortunately, the reports are a component of the User Interface assembly, not the Engine, so you would have to write your own reporting function to create a report using the API. For some example code of how to do this, send an e-mail to support@red-gate.com.


Do I have to distribute my license file with my application?

No. A properly compiled SQL Compare API application will not request a serial number when it is distributed.


How do I install my application on the client?

Copy your application and the assemblies it references to the same folder (or the Global Assembly Cache - not recommended). No registration or registry entries are required unless specifically requested by your application.

 

See Also

Getting Started with the SQL Compare API

Introduction to API Reference