Execute synchronization SCRIPT via .net sqlClient.SqlCOmmand
Warrenla
Posts: 5
We have a application we are push sql scripts to then it executes them to update the database on the clients computer (across the internet).
Anyway, I want to execute the synchronization script REDGATE generates, but as you all should know. It fails.. Any suggestions on how to pull this off?
we are using the .net framework 3.5 latest sp and C#
Anyway, I want to execute the synchronization script REDGATE generates, but as you all should know. It fails.. Any suggestions on how to pull this off?
we are using the .net framework 3.5 latest sp and C#
Comments
When executing a synchronization script created by the SQL Compare (or SQL Data Compare or using the Comparison SDK), it may be desired that some ad-hoc queries be intermixed with the SQL produced by the Red Gate APIs.
Because the BlockExecutor class can only run SQL code by converting ExecutionBlocks to SQL code and submitting them to the SQL Server, custom SQL cannot be introduced into the query stream. It is possible, however, to break an ExecutionBlock into individual query batches and running them using the .NET Framework's ADO .NET methods.
In the following C# example, first, a connection is made to the server using the connection properties of the second database. Then a transaction is created. The custom SQL query is run first, then each batch of SQL from the ExecutionBlock in order. Finally, the transaction is committed. If any errors occur during the execution of the SQL script, then the error is written to the console and the transaction will be rolled back.
I hope the above helps in resolving your issue.
Many Thanks
Eddie
Senior Product Support Engineer
Redgate Software Ltd
Email: support@red-gate.com