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

查看:29
本文介绍了我真的需要使用“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?

推荐答案

请记住,无论是否使用 XACT_ABORT,TRY-CATCH 都不会捕获某些错误.

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天全站免登陆