SqlException ErrorCodes

余生长醉 提交于 2019-12-06 07:28:58

I think, you should take a look at SqlExceptions Errors property and take a look at errors number which should point you to a message in master.dbo.sysmessages table.

Don't assume a specific error code always refers to the same problem.

select * from master.dbo.sysmessages where description like '%timeout%' 

This will give you all the following possible error messages - all with code 1033 :

The value provided for the timeout is not valid. Timeout must be a valid integer between 0 and 2147483647. 1033

Timeout occurred while waiting for latch: class '%ls', id %p, type %d, Task 0x%p : %d, waittime %d seconds, flags 0x%I64x, owning task 0x%p. Continuing to wait. 1033

Communications to the remote server instance '%.*ls' failed to complete before its timeout. The ALTER DATABASE command may have not completed. Retry the command. 1033

Database mirroring timeout value %d exceeds the maximum value 32767. 1033 Metadata cache entry %d:%d in database ID(%d) is not checked for coherency due to lock timeout. 1033

The marked transaction "%.*ls" failed. A timeout occurred while attempting to place a mark in the log by committing the marked transaction. This can be caused by contention with Microsoft Distributed Transaction Coordinator (MS DTC) transactions or other 1033

The Bulk Insert operation of SQL Server Destination has timed out. Please consider increasing the value of Timeout property on the SQL Server Destination in the dataflow. 1033

...and many many more errors in all languages.

So it's safe to assume 1033 means some kind of timeout? Unfortunately even that is not true:

select description from master.dbo.sysmessages where msglangid=1033

Warning: Fatal error %d occurred at %S_DATE. Note the error and time, and contact your system administrator.

Query not allowed in Waitfor.

Incorrect syntax near '%.*ls'.

The %S_MSG that starts with '%.*ls' is too long. Maximum length is %d. ORDER BY items must appear in the select list if the statement contains a UNION, INTERSECT or EXCEPT operator.

The ORDER BY position number %ld is out of range of the number of items in the select list.

and many many more non-timeout related errors.

So I'm sticking with :

IsSqlTimeout = ((ex as SqlException).Message.ToUpper().Contains("TIMEOUT");

So to actually answer your question - it depends on what your user actually is capable of understanding or should be told about.

I would suggest you log all errors (codes and message) over a period of time, group them and see which are most common to your environment.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!