gpt4 book ai didi

c# - 使用 .Number 捕获 mysql 异常

转载 作者:行者123 更新时间:2023-11-29 13:07:07 25 4
gpt4 key购买 nike

我想捕获编号为 1046 的特定 mysql 错误。如果我使用 MessageBox.Show 显示错误号,则无论它是哪个异常,它始终为 0。异常不应该有一个像 1046 这样的数字吗?

catch (MySqlException mysqlex)
{
MessageBox.Show(mysqlex.Number.ToString());
}

编辑:抱歉,我正在使用 MySQL-Connector/Net。

最佳答案

您看不到数字,因为您没有连接到数据库。也许 MySQL 正在为错误异常分配数字。

如果您查看 Number 属性 here 的描述它说

Gets a number that identifies the type of error. This number corresponds to the error numbers given in Server Error Codes and Messages.

因为您没有与服务器建立连接,所以无法获取服务器错误代码。

检查您的连接字符串。

关于c# - 使用 .Number 捕获 mysql 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22557433/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com