lunedì 7 aprile 2014

MysqlException Number Code List

When we catch exception using, for example, mysql net connector we can go deep and find out error.
We can discover error code, checking property Number of class MySqlException.



try
{
 connection.Open();
}
catch (MysqlException ex)
{
 switch (ex.Number)
                {

                    case 0:
                        return "Cannot connect to server";
                        break;

                    case 1045:
                        return "Invalid username/password, please try again";
                        break;                  

                 }
}

For a complete errors number list plaese referrer to http://dev.mysql.com/doc/refman/5.6/en/error-messages-server.html and in the share/errmsg.txt file