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.
The
Classproperty of theSqlErrorclass actually indicates the severity of the error. For the type of error, look in theNumberproperty. You can also use theMessageproperty to get a string describing the error. You can find the list of server error messages here.