是否有异常错误类值及其含义的列表?具体来说是sqlException

发布于 2025-01-08 10:12:57 字数 374 浏览 0 评论 0原文

我正在使用数据库并捕获异常来检查各种条件。我不能简单地捕获 sqlException,因为它可能意味着很多事情,并且通常用于

catch (SqlException e)
        {
            if (e.Errors[0].Class == 14)
            {
                return 0;
            }
            else ........

检查特定情况。在此示例中,类别 14(至少据我所知)表示重复条目。不同的类意味着找不到服务器,或拒绝连接,或登录错误等。有谁知道在哪里可以找到这些错误类的列表?谷歌搜索这一点很困难,因为任何带有“class”的东西都会变得显而易见。

I'm working some with a database and catching exceptions to check for various conditions. I can't simply catch the sqlException, since it can mean a lot of things, and usually use

catch (SqlException e)
        {
            if (e.Errors[0].Class == 14)
            {
                return 0;
            }
            else ........

To check for specific cases. In this example, class 14 (at least as far as I can tell) signifies a duplicate entry. A different class means the server can't be found, or refusing the connection, or login error, etc. Does anyone know where a list of these error classes could be found? Googling this is difficult since anything with "class" in it turns up the obvious.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

决绝 2025-01-15 10:12:57

严重性为 14 可能意味着很多事情:

SELECT message_id, [text]
FROM sys.messages
WHERE language_id = 1033
AND severity = 14;

要查看完整列表:

SELECT message_id, severity, [text]
FROM sys.messages
WHERE language_id = 1033
AND severity > 0
ORDER BY severity;

我怀疑您对 message_id 列比严重性列更感兴趣,因为它更具体一些。

A severity of 14 can mean a lot of things:

SELECT message_id, [text]
FROM sys.messages
WHERE language_id = 1033
AND severity = 14;

To see the full list:

SELECT message_id, severity, [text]
FROM sys.messages
WHERE language_id = 1033
AND severity > 0
ORDER BY severity;

I suspect you are more interested in the message_id column than the severity column, as that is a little more specific.

柏林苍穹下 2025-01-15 10:12:57

SqlError 类的 Class 属性实际上指示了错误的严重性。有关错误类型,请查看 Number 属性。您还可以使用消息属性来获取描述错误的字符串。您可以在此处找到服务器错误消息列表。

The Class property of the SqlError class actually indicates the severity of the error. For the type of error, look in the Number property. You can also use the Message property to get a string describing the error. You can find the list of server error messages here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文