我真的需要使用“SET XACT_ABORT ON”吗? [英] Do I really need to use "SET XACT_ABORT ON"?

查看:152
本文介绍了我真的需要使用“SET XACT_ABORT ON”吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您小心使用TRY-CATCH,并回滚错误,您真的需要使用:

if you are careful and use TRY-CATCH around everything, and rollback on errors do you really need to use:

SET XACT_ABORT ON

换句话说,TRY-CATCH是否会错过SET XACT_ABORT ON将会处理?

In other words, is there any error that TRY-CATCH will miss that SET XACT_ABORT ON will handle?

推荐答案

记住,TRY-CATCH不会捕获有或没有 XACT_ABORT的错误

Remember that there are errors that TRY-CATCH will not capture with or without XACT_ABORT.

但是, SET XACT_ABORT ON 不会影响错误的捕获。它确保任何事务回滚/注定。当OFF时,您仍然可以选择提交或回滚(取决于xact_state)。这是SQL 2005对 XACT_ABORT

的主要行为变化,它还是删除锁等,如果客户端命令超时启动,客户端发送中止指令。如果没有 SET XACT_ABORT ,如果连接保持打开状态,锁可以保留。我的同事(MVP),我在年初就彻底测试了。

What it also does is remove locks etc if the client command timeout kicks in and the client sends the "abort" directive. Without SET XACT_ABORT, locks can remain if the connection remains open. My colleague (an MVP) and I tested this thoroughly at the start of the year.

这篇关于我真的需要使用“SET XACT_ABORT ON”吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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