0

I have DbContextTransaction that does a commit at some point.

    using (DbContextTransaction transaction = dataContext.Database.BeginTransaction())
            {
                try
                {
                    .
                    .
                    transaction.Commit();
                }
                catch (Exception ex)
                {
                    transaction.Rollback();
                    throw;
                }
            }

and I want to increase the timeout for the commit operation. I read that it's very short and I had some timeout issues with that. How can I do it?

this is the error I'm getting

    Exception Message[An error was reported while committing a database transaction but it could not be determined whether the transaction succeeded or failed on the database server. See the inner exception and http://go.microsoft.com/fwlink/?LinkId=313468 for more information.] Type[System.Data.Entity.Infrastructure.CommitFailedException]  - System.Data.Entity.Infrastructure.CommitFailedException: An error was reported while committing a database transaction but it could not be determined whether the transaction succeeded or failed on the database server. See the inner exception and http://go.microsoft.com/fwlink/?LinkId=313468 for more information. ---> System.Data.SqlClient.SqlException: Execution Timeout Expired.  The timeout period elapsed prior to completion of the operation or the server is not responding. ---> System.ComponentModel.Win32Exception: The wait operation timed out
   --- End of inner exception stack trace ---

Thanks!

sgch
  • 77
  • 1
  • 7
  • Does this answer your question? [How do you configure the Transaction time out in Entity Framework 6 DbContext.Database.BeginTransaction?](https://stackoverflow.com/questions/19393089/how-do-you-configure-the-transaction-time-out-in-entity-framework-6-dbcontext-da) – Majid Hajibaba Dec 21 '21 at 11:00
  • increasing TransactionScope's timeout same as increasing the time for the complete function? – sgch Dec 21 '21 at 11:04
  • What do you mean by "the complete function"? Each statement you execute has a default command timeout. So even if the transaction timeout is one year, one statement can throw a timeout exception in 30s and cause the entire operation to fail in 30s. – Gert Arnold Dec 21 '21 at 11:36
  • TransactionScope has a Complete() function. I asked if increasing the timeout in the ctor of TransactionScope will also increase the timeout for the Complete() function? since the ctor's timeout is for the entire transactionScope and not specific for the Complete – sgch Dec 21 '21 at 12:10
  • Usually a commit doesn't take much time. Are you sure you get timeouts *specifically* on the `Commit()` call? (Or `Complete()`). If so, we really need to see more details of your code. Either way, there's no separate commit timeout, it's part of the entire transaction timeout. – Gert Arnold Dec 21 '21 at 12:17
  • I think there's an existing transaction locking the table and that's why the commit fail. I'm trying to fix it in my end. I updated the question with my error. As for the commit timeout so if i increase the transactionScope timeout or dataContext.Database.CommandTimeout it should increase the overall timeout including the commit/complete? – sgch Dec 21 '21 at 12:47

0 Answers0