The underlying provider failed on Commit, throwing a System.Data.EntityException.

.net entity-framework sqlclient sql-server transactions

Question

I saw many of the following errors last night in one of my projects using Entity Framework:

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()

This error is intriguing since data was really written to the database. I noticed that the error code discovered a relevant article on an MS website. seemed to be network-related.

I need help with a few issues, specifically:

  1. What choices do I have to fix this problem?
  2. Is the DB a potential suspect or is it most likely a network-related issue?
  3. How can I determine if the transaction really completed by looking at the code?
  4. Should I just retry the transaction or should I query the database on this error to see if success?
  5. If I do decide to retry the transaction, how can Entity Framework do this automatically, or do I just catch/retry?
  6. What additional stuff need I to be examining?

I appreciate it.

UPDATE

Using Spark for SQL, we were able to ascertain that a secondary SQL process from another group was hogging the CPU and interfering with the correct operation of our program. To put it briefly, we're going through with creating a second server to avoid additional disputes between the two teams.

The fact that the transaction really completed rather than failed makes the exception still intriguing.

1
19
12/9/2011 12:57:04 PM

Popular Answer

My guess is that the exception in your code was caused by the transaction commit command's success response not being delivered (or not being sent quickly enough). a rather bizarre edge case. Exceptions of this kind don't always indicate that the command's actual execution failed—only that there was a A problem.

In the same manner, it wouldn't necessarily follow that any side effects of a webservice request weren't used if there was a difficulty transmitting the answer.

1
5/24/2012 8:52:06 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow