locked
Entity Framework SaveChanges() exception RRS feed

  • Question

  • Hi, I am using MVC4 and entity framework to manage data. And I often met exception when I updating data, The code is :

    entities.Entry(obj).State = EntityState.Modified;
    entities.SaveChanges();

    And the exception is :

    System.Data.EntityException: The underlying provider failed on Commit. ---> System.Data.SqlClient.SqlException: The transaction operation cannot be performed because there are pending requests working on this transaction.
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
       at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
       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.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()

    Does anybody has idea about this error? I find this exception about once a day.

    Thanks.

    Yushan
    • Edited by Pigger9 Tuesday, October 29, 2013 4:54 PM
    Tuesday, October 29, 2013 4:50 PM

Answers

  • This code is not useful. Since the exception is originating from SaveChanges method, you must dig into that method as well.

    Please mark this post as answer if it solved your problem. Happy Programming!

    Tuesday, October 29, 2013 6:05 PM

All replies