SQL Server and EF Core, create “Lock Request Timeout” error

Bill Turner 1 Reputation point

(I asked this on StackOverflow as well, figured I'd throw it out here too)

I recently had my EF Core (2.1) code throw a DbUpdateException, caused by a lock request timeout. I think I understand the basic idea behind this (EF doesn't lock items until it tries to update, via SaveChanges() or SaveChangesAsync() - which is where the exception stack trace came through).

What I want to do is force the error condition, to verify that my handling of the exception is working correctly. I tried creating an open transaction on the same record in SSMS, but that gave me the general command timeout rather than the lock request timeout.

Any ideas on how to force this error for testing?

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
512 questions
Azure SQL Database
{count} votes

1 answer

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,496 Reputation points

    Hi BillTurner-1472,
    The default lock timeout limit is -1, which is unlimited.
    You can change the lock timeout limit in SSMS Options->Query Execution > Advanced.
    And one cause for this issue is to have uncommitted or non-rollback transactions.
    You can use implicit transactions, then run the update query without committing.
    Best Regards,
    Daniel Zhang

    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments