System.Data.EntityException:基础提供程序在提交时失败 [英] System.Data.EntityException: The underlying provider failed on Commit

查看:256
本文介绍了System.Data.EntityException:基础提供程序在提交时失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用实体框架,昨晚我的一个应用程序收到了以下一些例外情况:

Using Entity Framework, I received a number of the following exceptions last night in one of my applications:

System.Data.EntityException: The underlying provider failed on Commit. ---> 
System.Data.SqlClient.SqlException: Timeout expired.  The timeout period elapsed prior 
to completion of the operation or the server is not responding.     
    at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) 
    at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning()     
    at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error)
    at System.Data.SqlClient.TdsParserStateObject.ReadSni(DbAsyncResult asyncResult, TdsParserStateObject stateObj)
    at System.Data.SqlClient.TdsParserStateObject.ReadNetworkPacket()     
    at System.Data.SqlClient.TdsParserStateObject.ReadBuffer()     
    at System.Data.SqlClient.TdsParserStateObject.ReadByte()     
    at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler,SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)     
    at System.Data.SqlClient.TdsParser.TdsExecuteTransactionManagerRequest(Byte[] buffer, TransactionManagerRequestType request, String transactionName, TransactionManagerIsolationLevel isoLevel, Int32 timeout, SqlInternalTransaction transaction, TdsParserStateObject stateObj, Boolean isDelegateControlRequest)
    at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransactionYukon(TransactionRequest transactionRequest, String transactionName, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)     
    at System.Data.SqlClient.SqlInternalConnectionTds.ExecuteTransaction(TransactionRequest transactionRequest, String name, IsolationLevel iso, SqlInternalTransaction internalTransaction, Boolean isDelegateControlRequest)
    at System.Data.SqlClient.SqlInternalTransaction.Commit()     
    at System.Data.SqlClient.SqlTransaction.Commit()
    at System.Data.EntityClient.EntityTransaction.Commit()     
    --- End of inner exception stack trace ---     
    at System.Data.EntityClient.EntityTransaction.Commit()     
    at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)     
    at System.Data.Entity.Internal.InternalContext.SaveChanges()     
    at System.Data.Entity.Internal.LazyInternalContext.SaveChanges()

此错误的有趣之处在于,数据实际上已写入数据库。我在MS网站上找到了相关帖子似乎表明这是与网络相关的错误。

What's interesting about this error is that the data was actually written to the database. I found a related post on a MS site that seemed to indicate that this was a network related error.

我可以使用帮助的一些问题是:

A few questions that I could use assistance on are:


  1. 我必须为解决此错误而烦恼的哪些方法?

  2. 它是否可能与网络相关,或者数据库可能是可疑的?

  3. 如何从代码中判断事务是否确实完成了?

  4. 我应该查询该错误的数据库以检查是否成功或仅重试事务吗?

  5. 如果我重试事务,那么如何使用Entity Framework自动完成此操作,或者我只是捕获/重试?

  6. 还应该处理哪些其他项目?我在看吗?

  1. What options do I have to trouble shoot this error?
  2. Is it more than likely network related or could the DB be a suspect?
  3. How can I tell from the code whether the transaction really did complete?
  4. Should I query the DB on this error to check if success or simply retry the transaction?
  5. If I do retry the transaction, how can this be accomplished automatically with Entity Framework or do I simply catch/retry?
  6. What other items should I be looking at?

预先感谢。

更新

使用

Using Ignite for SQL we were able to determine that a secondary SQL process from another group was monopolizing the CPU preventing our application from functioning properly. In short, we're moving forward with adding a secondary server to prevent further conflicts between the two teams.

该例外仍然有趣,因为该交易实际上是成功的,

What's still interesting about the exception is that the transaction actually succeeded rather than failed.

推荐答案

我敢打赌,来自事务提交命令的成功响应未发送(或发送速度不够快)在您的代码中导致异常。有点疯狂的情况。此类异常不一定意味着命令的实际执行仅因 A 错误而失败。

My bet is that the success response from the transaction commit command was not sent (or not sent fast enough) causing an exception in your code. A kinda crazy edge case. Exceptions of this kind dont necessarily mean that the actual execution of the command failed just that there was A failure.

从网络服务调用发送响应时出现问题,这不一定表示未应用该调用的任何副作用。

In the same way if there was a problem sending the response from a webservice call it wouldn't necessarily imply that any side effects of that call were not applied.

这篇关于System.Data.EntityException:基础提供程序在提交时失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆