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.

Creating a deployment script without batch markers

When saving a deployment script produced by SQL Comparison SDK, you may want to save the script for later use by the ADO .NET client (SqlCommand). Since the script produced using SQL Toolkit's BlockSaver class in meant for SQL Server Management Studio, it includes batch separators (GO commands) that aren't understood by ADO .NET and will cause errors when run for this reason.

It is possible to save the SQL Toolkit ExecutionBlock in a way where batch markers are not included in the script by looping through the individual batches and saving only batches that are not marked as a batch marker. Here is an example code snippet which assumes that you have already populated an ExecutionBlock called "block":

  1. using (System.IO.StreamWriter sw=new System.IO.StreamWriter(@"c:\temp\test.sql"))
  2. {
  3. for (int i = 0; i < block.batchcount;="">
  4. {
  5. Batch b = block.GetBatch(i);
  6. if (b.Marker == false)
  7. {
  8. sw.Write(b.Contents + "\r\n");
  9. }
  10. }
  11. }


Please note that you may want to use the NoSqlPlumbing option as well when you create the ExecutionBlock to prevent transactional operations from appearing in the script. ADO .NET has its own methods for rolling back and committing transactions if necessary.

  1. work.BuildFromDifferences(stagingVsProduction, Options.Default | Options.NoSQLPlumbing, true);

Didn't find what you were looking for?