EntityException: The underlying provider failed on Commit RRS feed

  • Question

  • Hi,

    I got the following exception in SaveChanges():

    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.

    Since I've got this exception - I've handled it like the commit have failed .

    The problem is that the actual commit on the db WAS SUCCESSFUL and the SaveChanges was actually written to the db.

    It turns out that on this exception - you don't know if the save changes was successful or failure - similar to TransactionInDoubt exception while in TransactionScope . And in this case, you have to re-query the DB to know how to handle it right (check if changes were made or not).

    This seems like an unreasonable behavior:

    For each important SaveChanges() - you have to handle the following options:

    1. Success

    2. Exception:

       2.a. Failed

       2.b. Maybe - check on your own responsibility.


    Am I missing something here?

    I couldn't find any documentation regarding this issue, what is the right way to handle this exception?





    p.s. I was using EF 1.0


    Wednesday, November 3, 2010 10:32 AM

All replies

  • Hi Shlomi,

    So you are using TransactionScope ? Did you set the timeout of the TransactionScope ?

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, November 4, 2010 3:00 AM
  • Hi Alex,

    This error occurred not inside TransactionScope .

    I just pointed out that it is a similar case to the exception TransactionInDoubt that is thrown inside TransactionScope.


    Some more details:

    This error happened due to loss of connectivity with our DB - which caused the Timeout and in turn it 'failed on commit'.

    Unfortunately, I treated this exception - as failed to SaveChanges but it actually, on the DB, succeeded doing so, and then I lost the data integrity on my application in relation to the DB.


    I have to say that this is a really disturbing scenario.


    Thursday, November 4, 2010 9:07 AM
  • Hi,

    Just wanted to ping again on this issue, to see if someone have more insights.




    Tuesday, May 3, 2011 12:59 PM
  • Hi there,


    just wanted to say that I'm dealing with this issue too. It happens kind of randomly and in an environment with a "shady" connection to my database... if I run everything locally it's not an issue.

    Friday, May 6, 2011 1:57 PM
  • Hi,

    This exception occurs in my entityframework, did you have any solution yet?

    Friday, April 19, 2013 2:45 AM