【问题标题】:TransactionScope deadlocked issue in concurrencyTransactionScope 并发中的死锁问题
【发布时间】:2019-05-09 05:01:25
【问题描述】:

我在两台不同的服务器上有两个不同的数据库,我使用了TransactionScope。我是第一次使用TransactionScope

但是 在更新 Table1 时并发 我遇到了一个错误

事务(进程 ID 64)在锁定资源上与另一个进程死锁,并已被选为死锁牺牲品。重新运行事务。

查看TransactionScope网上相关文章

option.IsolationLevel = System.Transactions.IsolationLevel.ReadUncommitted;
option.Timeout = TimeSpan.FromMinutes(1);

using (_objTransactionScope = new TransactionScope(TransactionScopeOption.Required, option))
{
    //..Open Connection
    //..Process the Document
    //..Update Additional information in Table2 about document(Delete/Insert)   
    //..Update Location Information in Table3 about document(Delete/Insert)
    //..Delete the Document in Table4 in Differant Database on Differant Server(WCF Service)
    //..Update the Checksum of the Document and Metadata in Table1(Deadlock Error in concurrency)
    //..Delete Lock Entry From Table5   
    //..Close Connection
    //..Commit Transaction Scope
}

【问题讨论】:

  • 一次只有一个进程连接到数据库,您无法收到此错误。所以有些事情你没有在这里发布,我们无法帮助你解决我们不知道的事情。请发布minimal reproducible example 并添加任何必要的其他信息。
  • 请检查更新的详细信息..

标签: c# transactionscope


【解决方案1】:

当两个用户锁定不同的对象并且每个用户都希望锁定另一个对象时,就会发生死锁。发生这种情况时,SQL Server 通过自动选择一个并中止进程来结束死锁,从而允许另一个进程继续。被中止的事务被回滚,并且错误消息被发送给被中止进程的用户。通常,需要最少开销来回滚的事务是被中止的事务。

解决方案: 死锁优先级可由用户设置。换句话说,用户可以选择应该停止哪个进程以允许其他进程继续。 SQL Server 自动选择要终止的进程,该进程正在运行完成锁的循环链。有时,它会选择运行时间比其他进程短的进程。

read this article

【讨论】:

    猜你喜欢
    • 2019-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-28
    • 2012-04-22
    • 1970-01-01
    相关资源
    最近更新 更多