views:

195

answers:

2

I have an exception handler for the type SqlException and I'm looking at the SqlException.Number property of the exception to determine if a dead-lock occurred (1205). I'm currious, instead of writing SqlException.Number == 1205, is there an enum I can refer to that would produce something similar to SqlException.Number == SqlExceptionNumberEnum.DeadLockVictim?

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

A: 

Not that I know of. In particular, you can define your own error numbers with sp_addmessage, and the errors change (grow) per SQL-Server version, so it would quickly be a problem if (for example) you were using .NET 2.0 with SQL Server 2008, as your numbers would exist.

Marc Gravell
A: 

Unfortunately I don't think this is feasible. If you run the following query,

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

it produces over six thousand rows. You could write a small app to parse the table and produce a C# class with const properties representing each message, but it's probably not worth the effort.

tbreffni