sql transaction don't roll back

孤人 提交于 2019-12-24 05:13:03

问题


In transact-sql, what is the purpose of enclosing different actions between "begin transaction" and "commit transaction"

I noticed that when an exception is thrown in the middle of the function It Does not roll back the transaction. if an error occurs, How to roll back the transaction?


回答1:


Best way to have proper error handling using try and catch. Then do actions in catch clause based on the error like roll back tran or etc.

However, if you do not want to change the code at all.Specify following before your code execution.

set xact_abort on

This will cause auto rollback of transaction.But best soltuion will be to catch and handle errors properly.



来源:https://stackoverflow.com/questions/11481345/sql-transaction-dont-roll-back

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!