gpt4 book ai didi

c# - 如果在 Using block 末尾未调用 TransactionScope.Complete,Transaction 会发生什么

转载 作者:太空狗 更新时间:2023-10-30 00:59:54 25 4
gpt4 key购买 nike

我正在使用 SQL Server 2012,并且在 TransactionScope Using block 中有多个到同一数据库的 SQL 连接。但是,如果第一个更新 SQL 操作没有产生所需的输出,那么我将跳过对 SQL 操作的下一次调用,并且还调用 TransactionScope.Complete 未在 Using block 的末尾调用.

最佳答案

您需要的大部分信息都在这里很好地列出了 Completing a transaction scope

When your application completes all the work it wants to perform in a transaction, you should call the Complete method only once to inform the transaction manager that it is acceptable to commit the transaction. It is very good practice to put the call to Complete as the last statement in the using block.

Failing to call this method aborts the transaction, because the transaction manager interprets this as a system failure, or equivalent to an exception thrown within the scope of the transaction. However, calling this method does not guarantee that the transaction wil be committed. It is merely a way of informing the transaction manager of your status. After calling the Complete method, you can no longer access the ambient transaction by using the Current property, and attempting to do so will result in an exception being thrown.

关于c# - 如果在 Using block 末尾未调用 TransactionScope.Complete,Transaction 会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52032869/

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