我正在得到一个SqlException
在.NET 3.5应用程序的日志中,我正在寻找相应的数字(属性值SqlException.Number
).
System.Data.SqlClient.SqlException: A transport-level error has occurred
when receiving results from the server. (provider: TCP Provider, error: 0
- The specified network name is no longer available.) at
System.Data.SqlClient.SqlConnection.OnError
我也收到错误,例如:
System.Data.SqlClient.SqlException: A network-related or instance-specific error
occurred while establishing a connection to SQL Server. The server was not found
or was not accessible. Verify that the instance name is correct and that SQL Server
is configured to allow remote connections.
有谁知道如何正确捕获这些异常? (您也可以发布您的答案here https://stackoverflow.com/questions/380547/a-list-of-common-sqlexception-numbers)
该特定错误并非来自 SQL Server 中的 sys.messages - 因为它是连接问题。所以我手头没有号码。
说实话,您应该做的最好的事情是确保将号码写到日志中,但有例外 - 这样,您将始终在日志中并排显示号码和消息。可能无法回答您当前的问题,但恕我直言,这将是最好的进展。不仅SqlException.Number
but SqlException.ErrorCode
也是——我认为在这样的情况下.ErrorCode
可能是您真正需要的(不确定不检查)。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)