catch mysql-exception使用.Number [英] catch mysql-exception using .Number
问题描述
我想捕获一个特定的mysql错误与数字1046.
如果我使用MessageBox.Show显示错误号,它总是0,无论是哪个异常。异常不应该有一个数字1046?
I want to catch a specific mysql error with the number 1046. If i use MessageBox.Show to display the error number it is always 0, no matter which Exception it is. Shouldn't the Exception have a number like the number 1046?
catch (MySqlException mysqlex)
{
MessageBox.Show(mysqlex.Number.ToString());
}
编辑:对不起,我使用MySQL-连接器/ p>
Sorry, i am using the MySQL-Connector / Net.
推荐答案
您没有看到一个数字,因为您没有连接到数据库。
可能MySQL正在为错误异常分配数字。
You don't see a number because you did not connect to a database. And probably MySQL is assigning numbers to error exceptions.
如果你看一下Number属性的描述这里它说
If you look at description for Number property here it says
获取一个标识错误类型的数字。此数字对应于服务器错误代码和消息中给出的错误编号。
Gets a number that identifies the type of error. This number corresponds to the error numbers given in Server Error Codes and Messages.
检查您的连接字符串。
这篇关于catch mysql-exception使用.Number的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!