DEV Community

baris
baris

Posted on

Answer: How to catch SqlException caused by deadlock?

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 
    }

Top comments (0)