Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a list of exception error class values and what they mean? Specifically sqlexception

I'm working some with a database and catching exceptions to check for various conditions. I can't simply catch the sqlException, since it can mean a lot of things, and usually use

catch (SqlException e)
        {
            if (e.Errors[0].Class == 14)
            {
                return 0;
            }
            else ........

To check for specific cases. In this example, class 14 (at least as far as I can tell) signifies a duplicate entry. A different class means the server can't be found, or refusing the connection, or login error, etc. Does anyone know where a list of these error classes could be found? Googling this is difficult since anything with "class" in it turns up the obvious.

like image 583
cost Avatar asked Dec 27 '22 05:12

cost


1 Answers

A severity of 14 can mean a lot of things:

SELECT message_id, [text]
FROM sys.messages
WHERE language_id = 1033
AND severity = 14;

To see the full list:

SELECT message_id, severity, [text]
FROM sys.messages
WHERE language_id = 1033
AND severity > 0
ORDER BY severity;

I suspect you are more interested in the message_id column than the severity column, as that is a little more specific.

like image 191
Aaron Bertrand Avatar answered Feb 08 '23 22:02

Aaron Bertrand