| Author |
Message |
ampo
Joined: 21 May 2009 Posts: 8
|
Posted: Mon May 25, 2009 10:47 am Post subject: Manipulate execution block |
|
|
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 |
|
 |
Brian Donahue
Joined: 23 Aug 2004 Posts: 6348 Location: Red Gate Software
|
Posted: Thu May 28, 2009 6:24 pm Post subject: |
|
|
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. _________________ Brian Donahue
Technical Support
Red Gate Software Ltd.
44 (0)870 160 0037 ext 8521
US and CAN 1-866-RED GATE ext 8521 |
|
| Back to top |
|
 |
|
|
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