sql事务不回滚 [英] sql transaction don't roll back

查看:82
本文介绍了sql事务不回滚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在transact-sql中,在开始交易和提交交易之间包含不同动作的目的是什么

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?

推荐答案

使用try进行正确错误处理的最佳方法赶上。然后根据诸如roll back tran等之类的错误在catch子句中执行操作。

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.

这篇关于sql事务不回滚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆