SQLEXCEPTION编号的方法 [英] How is SqlException Number assigned
问题描述
SQLEXCEPTION 有属性的号
再有是这样的: http://msdn.microsoft.com/en -us /库/ cc645603.aspx
和这样的:的http://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx
和它似乎是一个或另一个
And it seems to be one or the other
问:
如何是决定哪些?
原因FOR问:
我需要捕捉特定的的SQLException ,然后决定如何根据号属性来对付他们,但我不知道我应该看时,似乎哪个列表如系统使用的是两个消息,我不知道是什么标准用于选择。
I need to catch certain SqlExceptions and decide how to deal with them based on the Number property but I don't know which list I should look at when it seems like the system is using messages from both, and I don't know what criteria is used for choosing.
例如:
- 第53号 - 从服务器错误消息列表(存在于两个)
- 在数10054 - 从系统错误信息列表(存在于两个)
- 在数-1 - 从服务器错误消息列表(只存在于服务器列表)
- 在数121 - 从系统错误信息列表(存在于两个) ......
- Number 53 - from server error message list (exists on both)
- Number 10054 - from system error message list (exists on both)
- Number -1 - from server error message list (exists only on server list)
- Number 121 - from system error message list (exists on both) ......
推荐答案
从理论上说,它是SQL的错误号码,例如。在服务器端 ERROR_NUMBER()
。换句话说,第一列表。
The theory goes that is the SQL error number, eg. the server side ERROR_NUMBER()
. In other words, the first list.
然而也有一些发生在客户端,而不是在服务器端报告的SqlClient异常。一个典型的例子是像无法连接到服务器上的错误,因为你没有连接没有服务器端错误可言。例如,一个坏的服务器名(在DNS中没有解决),在这种情况下,的InnerException
将指向走向的<a href =http://msdn.microsoft.com /en-us/library/system.componentmodel.win32exception.aspx相对=nofollow> Win32Exception
与<一个href="http://msdn.microsoft.com/en-us/library/system.componentmodel.win32exception.nativeerror$c$c.aspx"相对=nofollow> NativeError code
中的 ERROR_BAD_NETPATH
。在这种情况下53,OS系统错误code,将被报告为SQLEXCEPTION错误号。
However there are a number of exceptions reported by SqlClient that occur on the client side, not on the server side. A typical example would be an error like failure to connect to the server, since you did not connect there is no server side error to speak of. For example a bad server name (does not resolve in DNS), in such cases the InnerException
will point toward a Win32Exception
with NativeErrorCode
value of ERROR_BAD_NETPATH
. In this case 53, the OS system error code, will be reported as SqlException error number.
其他情况报告的SqlClient中错误的是一个套接字错误,就像突然断开。再次,没有服务器端的错误可言,而SQLException都将被包装类型的 SocketException
(Win32Error的一个子类)的<一个href="http://msdn.microsoft.com/en-us/library/system.componentmodel.win32exception.nativeerror$c$c.aspx"相对=nofollow> NativeError code
著名的WSA错误号之一的,像 WSAECONNRESET
。在这种情况下,在 SqlException.ErrorNumber
将是10054,但是10054从WSA范围,而不是10054从SQL Server的误差范围内。我知道......
Other cases the error reported by the SqlClient is a socket error, like an abrupt disconnect. Again, there is no 'server side' error to speak of, and the SqlException will wrap an InnerException of type SocketException
(a subclass of Win32Error) with the NativeErrorCode
of one of the well known WSA error numbers, like WSAECONNRESET
. In this case the SqlException.ErrorNumber
will be 10054, but is the 10054 from the WSA range, not the 10054 from the SQL Server errors range. I know...
那么,你该怎么办?请确保您检查的InnerException
,如果是 Win32Exception
则 ErrorNumber
从系统错误code(操作系统错误)的到来。否则,它应该是一个SQL Server的错误号。
So what are you supposed to do? Make sure you check the InnerException
, if is a Win32Exception
then the ErrorNumber
is coming from a system error code (OS error). Otherwise it should be a SQL Server error number.
呵呵,再有就是 1
...我的认为的报告通过的SqlClient本身(如一些内部状态错误)但我不知道。
Oh, and then there is -1
... I think that is reported by SqlClient itself (eg. some internal state errors) but I'm not sure.
这篇关于SQLEXCEPTION编号的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!