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?
我有一个SqlException类型的异常处理程序,我正在查看异常的SqlException.Number属性,以确定是否发生了死锁(1205)。我很奇怪,而不是写SqlException.Number == 1205,有没有我可以引用的枚举,它会产生类似于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!
由于潜在的错误消息/数字的剪切量,这可能是不可行的,但认为值得询问。谢谢!
2 个解决方案
#1
1
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.
从来没听说过。特别是,您可以使用sp_addmessage定义自己的错误号,并且每个SQL-Server版本的错误都会发生变化(增长),因此如果(例如)使用.NET 2.0和SQL Server 2008,则很快就会出现问题。你的号码会存在。
#2
1
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.
它产生超过六千行。您可以编写一个小应用程序来解析表并生成一个C#类,其中const属性代表每条消息,但它可能不值得付出努力。
#1
1
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.
从来没听说过。特别是,您可以使用sp_addmessage定义自己的错误号,并且每个SQL-Server版本的错误都会发生变化(增长),因此如果(例如)使用.NET 2.0和SQL Server 2008,则很快就会出现问题。你的号码会存在。
#2
1
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.
它产生超过六千行。您可以编写一个小应用程序来解析表并生成一个C#类,其中const属性代表每条消息,但它可能不值得付出努力。