Manipulate execution block

Automate and integrate using the SQL comparison API

Moderator: Chris Auckland

Manipulate execution block

Postby ampo » Mon May 25, 2009 10:47 am

Hello.

I got the execution block and manipulated it by getting its value (ToString()) to string variable.
Now I want to execute the updated string.

How can I set it back to the block?
Any other way?

Thanks.
ampo
 
Posts: 8
Joined: Thu May 21, 2009 7:19 am

Postby Brian Donahue » Thu May 28, 2009 6:24 pm

Hi Amir,

As far as I am aware, you cannot make changes to the ExecutionBlock script and write it back. What you could do is to execute your own bespoke SQL code in-line with the SQL batches contained in the ExecutionBlock using a standard ADO .NET connection. Here is some sample code here that explains how to do it.
Code: Select all
Work w=new Work();
bool quiet=false;
w.BuildFromDifferences(diffs, options, true);
            if (!quiet) Console.WriteLine("Synchronizing database");
            SqlTransaction trans=null;
            int batNum = 0; // current batch number
                conn.ChangeDatabase(databaseName);
                cmd = conn.CreateCommand();
                cmd.CommandTimeout = queryTimeout;
                trans = conn.BeginTransaction(System.Data.IsolationLevel.Serializable, "MainTransaction");
                cmd.Transaction = trans;   
//Execute your own stuff before SQL Compare's stuff
                        cmd.CommandText = "UPDATE MyTable SET something=somethingelse";
                        cmd.ExecuteNonQuery();
                for (batNum = 0; batNum < w.ExecutionBlock.BatchCount; batNum++)
                {
                    Batch b=w.ExecutionBlock.GetBatch(batNum);
                    if (!b.Marker)
                    {
                        cmd.CommandText = b.Contents;
                        cmd.ExecuteNonQuery();
                    }
                    if (!quiet) Console.Write(String.Format("    \\r{0}%\\r", (int)((batNum / (double)w.ExecutionBlock.BatchCount) * 100)));
                }
            trans.Commit();
            if (!quiet) Console.WriteLine("Synchronization successful");
           
Note well: the synchronization script was produced with the option to produce transactional plumbing off, otherwise setting up the transactions using C# code will fail.
Brian Donahue
 
Posts: 6669
Joined: Mon Aug 23, 2004 10:48 am


Return to SQL Comparison SDK Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests