Bug #37398 Unknown MySqlErrorCode encountered opening connection with a wrong password
Submitted: 13 Jun 2008 15:20 Modified: 11 Jul 2008 13:13
Reporter: sylvain petreolle Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:5.2.2 OS:Windows (2003 SP2)
Assigned to: CPU Architecture:Any

[13 Jun 2008 15:20] sylvain petreolle
Description:
I am trying to connect to a mysql database with a wrong password using Connector/Net.
The returned MySqlException.Number equals to 1045,
which doesnt match any member of the MysqlErrorCode enumeration.

The MySQL server version is a 5.0.32-7etch5, running on 
Linux Debian 2.6.18-6-486

How to repeat:
cnnConnection.ConnectionString = "Server=myserver;User id='invaliduser';Password='invalidpassword';Database=mybase"
            try
            {
                cnnConnection.Open();
            }
            catch (MySqlException ex)
            {
                string message="";
                switch ((MySqlErrorCode)ex.Number)
                {
                }
            }
[16 Jun 2008 12:08] Tonci Grgin
Hi Sylvain and thanks for your report.

I can not repeat it since ERROR 1045 *is* defined in latest sources I use:
MySQLError.cs, ln: 129
--<cut>--
            UnableToConnectToHost = 1042,
/*                ER_HANDSHAKE_ERROR 1043
                ER_DBACCESS_DENIED_ERROR 1044
                ER_ACCESS_DENIED_ERROR 1045
                ER_NO_DB_ERROR 1046
--<cut>--

which exactly matches server's error both in ErrCode and in error text:
C:\mysql-5-0-64-pb1103-win32\bin>mysql -uroot -p -P5064 test
Enter password: ********
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: Y
ES)

Test case:
    MySqlConnection conn = new MySqlConnection();
    conn.ConnectionString = "DataSource=localhost;Database=test;UserID=root;Password=tupello;PORT=5064;Allow Zero Datetime=True;logging=True;";
    try
    {
        conn.Open();
        conn.Close();
    }
    catch (MySqlException ex)
    {
        Assert.AreEqual(1045, ex.Number);
        Assert.Fail(ex.Message);
    }
[17 Jun 2008 9:38] sylvain petreolle
Hi Tonci,

Your snippet shows that
ER_ACCESS_DENIED_ERROR 1045
is defined but still into comments and not known from the enum.

Your test case also uses the literal value and not a enum constant.
[17 Jun 2008 12:33] Tonci Grgin
Sylvain, thanks for pointing out to me the error in thinking. True, verified just as described by looking into code for MySqlErrorCode.
Workaround is simple and obvious, we need to add 1045 there.
[17 Jun 2008 15:26] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/48015
[17 Jun 2008 15:27] Reggie Burnett
Fixed in 5.1.7 and higher
[9 Jul 2008 8:39] Tony Bedford
Just a quick check. Looking at the patch, the fix appears to have gone into 5.1.6 (or I may have misinterpreted the patch). Should this change appear in the 5.1.6 or 5.1.7 changelog? Thanks!
[9 Jul 2008 17:11] Reggie Burnett
5.1.7
[11 Jul 2008 13:13] Tony Bedford
An entry has been added to the 5.1.7 changelog:

An unknown MySqlErrorCode was encountered when opening a connection with an incorrect password.