SQL Error Number SqlClient Enumeration Type

I have an exception handler for the SqlException type, and I look at the SqlException.Number property of the exception to determine if deadlock has occurred (1205). I am currious, instead of writing SqlException.Number == 1205, is there an enumeration that I can reference that will create something similar to SqlException.Number == SqlExceptionNumberEnum.DeadLockVictim?

This may not be feasible due to the shear volume of potential error messages / numbers, but thought it was worth it. Thanks!

+7
sql-server
source share
2 answers

Not that I knew. In particular, you can determine your own error numbers using sp_addmessage , and the errors will change (be expressed) to the version of the SQL server, so this will quickly become a problem if (for example) you used .NET 2.0 with SQL Server 2008, since your numbers will exist.

+1
source share

Unfortunately, I do not think this is possible. If you run the following query,

 select * from sys.messages where language_id=1033 and severity between 11 and 16 

he produces more than six thousand lines. You can write a small application to parse a table and create a C # class with const properties representing each message, but this is probably not worth the effort.

+1
source share

All Articles