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());
}
EDIT: Sorry, i am using the MySQL-Connector / Net.
解决方案
You don't see a number because you did not connect to a database.
And probably MySQL is assigning numbers to error exceptions.
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.
Because you did not made a connection to the server you cannot get server error code.
Check your connection string.