Red Gate forums :: View topic - Manipulate execution block
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Comparison SDK Previous Versions
SQL Comparison SDK Previous Versions forum

Manipulate execution block

Search in SQL Comparison SDK Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
ampo



Joined: 21 May 2009
Posts: 8

PostPosted: Mon May 25, 2009 10:47 am    Post subject: Manipulate execution block Reply with quote

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.
Back to top
View user's profile Send private message
Brian Donahue



Joined: 23 Aug 2004
Posts: 6642

PostPosted: Thu May 28, 2009 6:24 pm    Post subject: Reply with quote

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:

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.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group