Manipulate execution block

ampoampo Posts: 16

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?



  • Brian DonahueBrian Donahue Posts: 6,590 New member
    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.
    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
                    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";
                    for (batNum = 0; batNum < w.ExecutionBlock.BatchCount; batNum++)
                        Batch b=w.ExecutionBlock.GetBatch(batNum);
                        if (!b.Marker)
                            cmd.CommandText = b.Contents;
                        if (!quiet) Console.Write(String.Format("    \r{0}%\r", (int)((batNum / (double)w.ExecutionBlock.BatchCount) * 100)));
                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.
Sign In or Register to comment.