gpt4 book ai didi

sql - 当连接关闭时,未提交的事务会发生什么?

转载 作者:行者123 更新时间:2023-12-01 18:18:15 24 4
gpt4 key购买 nike

它们会立即回滚吗?一段时间后它们会回滚吗?他们是否处于未 promise 状态?

如果使用连接池并且简单地重置连接,行为是否相同?

最佳答案

在应用连接池时它可以保持打开状态。示例:命令超时可以留下锁和 TXN,因为客户端发送为“中止”。

2个解决方案:

  • 在客户端进行测试,字面意思是:

    IF @@TRANCOUNT <> 0 ROLLBACK TRAN

  • 使用SET XACT_ABORT ON确保 TXN 被清理:Question 1Question 2

我总是使用SET XACT_ABORT ON .

来自this SQL Team blog :

Note that with connection pooling, simply closing the connection without a rollback will only return the connection to the pool and the transaction will remain open until later reused or removed from the pool. This can result in locks begin held unnecessary and cause other timeouts and rolling block

来自MSDN ,“交易支持”部分(我的粗体)

When a connection is closed, it is released back into the pool and into the appropriate subdivision based on its transaction context. Therefore, you can close the connection without generating an error, even though a distributed transaction is still pending. This allows you to commit or abort the distributed transaction at a later time.

关于sql - 当连接关闭时,未提交的事务会发生什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1539564/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com