SQL Compare bad transaction management
jesperkt
Posts: 5
Hi, I am having a problem making SQL Compare generate usable script (with a functional transaction roll back mechanism) when using Migration Scripts.
We often use SQL Compare to generate DB script to be run on our customer's databases. If the intermediary SVN checkin(s) contain only auto generated code (i.e. no migration script), SQL Compare adds the following code block after every GO
This ensures that the script is fully rollbacked if an error occurs at any time during the execution.
Unfortunately, if the intermediary SVN checkin has a Migration Script, these blocks of code are not added. Though the resulting script still has a BEGIN/ROLLBACK/COMMIT TRANSACTION block these do not really do anything useful. Any error in the middle of the script will result in partial commits.
I hope someone can help me with this problem. Hopefully I am merely missing a setting somewhere.
We often use SQL Compare to generate DB script to be run on our customer's databases. If the intermediary SVN checkin(s) contain only auto generated code (i.e. no migration script), SQL Compare adds the following code block after every GO
IF @@ERROR<>0 AND @@TRANCOUNT>0 ROLLBACK TRANSACTION GO IF @@TRANCOUNT=0 BEGIN INSERT INTO #tmpErrors (Error) SELECT 1 BEGIN TRANSACTION END GO
This ensures that the script is fully rollbacked if an error occurs at any time during the execution.
Unfortunately, if the intermediary SVN checkin has a Migration Script, these blocks of code are not added. Though the resulting script still has a BEGIN/ROLLBACK/COMMIT TRANSACTION block these do not really do anything useful. Any error in the middle of the script will result in partial commits.
I hope someone can help me with this problem. Hopefully I am merely missing a setting somewhere.
Jesper Thygesen
Comments
If I attempt to add a Migration Script to this check in, the following code is generated for me (note that I have removed a lot of lines to make my case more clear to the reader).
Now I do not change this code, but I still save it as a migration script. Then I use SQL Compare to generate a script for me that I can use to add this change to an foreign database. The resulting code will looks something like this.
Since we never put anything inside the #tmpErrors table, this transaction will never rollback, and we could end up with a partial check in (maybe not in this simplified case, but in more complex ones).
If I delete my migration script and try SQL Compare again, it generates much better code:
This code IS transaction safe. Either it will all be committed or none of it will.
Since a bug has been logged, does this mean that Migration Script SHOULD have been padded with the be padded with the code below after every command?
Thanks a lot for providing information about SQL Compare.SQL Queries can be used to retrieve large amounts of records from a database quickly and efficiently.SQL databases use long-established standard which is being
adopted by ANSI & ISO. Non-SQL databases do not adhere to any clear standard.
I think you have replied to the wrong post. Your reply has no relevance for this subject.