SQL Comparison SDK 10

Help for older versions available.

These pages cover SQL Comparison SDK 10, which is not the latest version. Help for other versions is also available.

Running SQL code inside SQL Comparison SDK applications

In some cases, you may want to augment the script produced by the SQL Compare or SQL Data Compare API with SQL code that you have written yourself.

SQL Comparison SDK can compare and synchronize schema and data between two instances of SQL Server, however the API is limited to executing the code produced by the API. For instance, an object called BlockExecutor can run the SQL commands contained in an ExecutionBlock object, but it cannot run a SQL statement that you have written yourself.

In order to execute these "custom" SQL Scripts, the libraries provided by ADO .NET would be the choice for running your own SQL code. In the following example, a SqlCommand object is used to run a SQL command that will create a table in the WidgetStaging database.

C# code Toggle source code

  1. using System.Data.SqlClient;
  2. ...
  3. CreateCommand("CREATE TABLE [test](id int, data varchar(50))", "Data Source=localhost;Initial Catalog=WidgetStaging;Integrated Security=SSPI");
  4. ...
  5. private static void CreateCommand(string queryString,
  6. string connectionString)
  7. {
  8. using (SqlConnection connection = new SqlConnection(
  9. connectionString))
  10. {
  11. SqlCommand command = new SqlCommand(queryString, connection);
  12. command.Connection.Open();
  13. command.ExecuteNonQuery();
  14. connection.Close();
  15. }
  16. }

Didn't find what you were looking for?