【问题标题】:"Server failed to resume the transaction" error in SQL Server 2008 + .NET3.5 + LINQSQL Server 2008 + .NET3.5 + LINQ 中的“服务器无法恢复事务”错误
【发布时间】:2011-04-23 03:30:08
【问题描述】:

aspx.cs 代码: 代码本身很大,这里的代码是虚构的,但它看起来(重要的部分)是这样的:

foreach (Transaction trans in vTransactionList)
        {
            switch (trans)
            {
                case 201: codehere; break;
                case 202: codehere; break;
                case 203: 
                       vProcesso.MarcaEnvioServico(
                                    trans.ProcessId,
                                    trans.CodTrans);
                       break;

            }
        }     

业务类方法:

            RENDataContext db = new RENDataContext();

            Processo update = tabela.SingleOrDefault(
                x => x.CodTrans == pCodTrans);

            update.SentDate= DateTime.Now;
            update.ProcessId = pProcessId;
            update.LogUsuario = pUsuario_Id;
            update.LogVersaoRegistro = servico.LogVersaoRegistro + 1;
            update.LogDataAlteracao = DateTime.Now;

            db.SubmitChanges();

有时(在执行此代码时,我经常收到此错误(sqlserverexception):“服务器无法恢复事务。”同样,它只是随机的,有时它执行,有时它不执行。当它首先失败时在一段时间内一直失败。

我使用存储过程而不是那个 LINQ 代码来更新表,并且发生了同样的问题。

【问题讨论】:

  • 什么是 vCodTrans ... 它应该是反式的吗?

标签: c# asp.net linq sql-server-2008 .net-3.5


【解决方案1】:

您可能想查阅此链接: server failed to resume transaction。我所看到的这个错误的总结是多个命令正在使用单个连接执行。当根据 SQL Server 提交或回滚时,客户端代码会混淆仍然有效的事务。在查看业务类方法的代码时,我注意到上下文不在 using 语句中。上下文类应该实现 IDisposable,因此在使用完上下文后应该调用 Dispose。您可以尝试将代码更改为:

            using(RENDataContext db = new RENDataContext()){

                Processo update = tabela.SingleOrDefault(
                    x => x.CodTrans == pCodTrans);

                update.SentDate= DateTime.Now;
                update.ProcessId = pProcessId;
                update.LogUsuario = pUsuario_Id;
                update.LogVersaoRegistro = servico.LogVersaoRegistro + 1;
                update.LogDataAlteracao = DateTime.Now;

                db.SubmitChanges();
            }

看看这是否不能解决您的问题。

【讨论】:

  • 这确实是一个可能的解决方案,我会尝试并在这里回复
  • 此答案中的链接已损坏。
猜你喜欢
  • 2010-11-26
  • 1970-01-01
  • 2014-05-20
  • 1970-01-01
  • 1970-01-01
  • 2015-12-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多