DEV Community


Answer: How to catch SqlException caused by deadlock?

boyukbas profile image baris ・1 min read

try catch deadlock sql server

The Microsft SQL Server-specific error code for a deadlock is 1205 so you'd need to handle the SqlException and check for that. So, e.g. if for all other types of SqlException you want the bubble the exception up:

catch (SqlException ex)
    if (ex.Number == 1205)
        // Deadlock 

Discussion (0)

Editor guide