Bug #73610 Mysql Extension for .NET doesn't show correct Exception number.
Submitted: 16 Aug 2014 11:43 Modified: 20 Jan 2023 19:30
Reporter: Alakbar Valiyev Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:Mysql.Data DLL 6.8.3 (for.NET), MySQL Connector/Net 6.9.3 OS:Windows (Windows7)
Assigned to: CPU Architecture:Any
Tags: .net, exception, exceptionnumber

[16 Aug 2014 11:43] Alakbar Valiyev
Description:
Hi,
I can connect to Mysql database with C# without problem. But if I change correct password to non-correct one, I should get exception with the number 1045. But it doesn't work. It gives exception with wrong number.

Example:
    protected void Page_Load(object sender, EventArgs e)
    {
        MySqlConnectionStringBuilder connstring = new MySqlConnectionStringBuilder { Server = "localhost", Password = "rooter",UserID="root",Database="newbase" };
        MySqlConnection connection = new MySqlConnection(connstring.ToString());
        try
        {
            connection.Open();
        }
        catch (MySqlException ex)
        {
            switch (ex.Number)
            {
                case 1049: Response.Write("invalid database");
                    break;
                case 1045: Response.Write("Login failed");
                    break;
                default: Response.Write("The number of exception is "+ex.Number.ToString());
                    break;
            }
        }
        connection.Close();
    }

Above code is without problem. Bu if i will add some character to my password string, I 'm getting output "The number of exception is 0".
Another example: if i'm changing correct database name with the incorrect one (Database="blablabla") . i still get the 0 (zero) exception number. 
Only if, when I'm writing incorrect server name(Server = "blahblahblah") then I'm getting correct exception numebr as below:
"The number of exception is: 1042"

How to repeat:
Add Mysql extension to .NET project (I tried with the ASP.NET project). Then paste below script to the Default.aspx.cs file:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MySql.Data.MySqlClient;

public partial class Website_MasterPage : System.Web.UI.MasterPage
{
    protected void Page_Load(object sender, EventArgs e)
    {
        MySqlConnectionStringBuilder connstring = new MySqlConnectionStringBuilder { Server = "localhoslt", Password = "rooter",UserID="root",Database="newbase1" };
        MySqlConnection connection = new MySqlConnection(connstring.ToString());
        try
        {
            connection.Open();
        }
        catch (MySqlException ex)
        {
            switch (ex.Number)
            {
                case 1049: Response.Write("invalid database");
                    break;
                case 1045: Response.Write("Login failed");
                    break;
                default: Response.Write("The number of exception is: "+ex.Number.ToString());
                    break;
            }
        }
        connection.Close();
    }
}

Suggested fix:
Need to check Mysql Extension for .NET. MysqlException class.
[12 Nov 2014 6:54] Chiranjeevi Battula
Hello  Alakbar Valiyev,

Thank you for the bug report and test case.
Verified this behavior on Visual Studio 2013 (C#.Net) with  MySQL Connector/Net 6.9.3.

Thanks,
Chiranjeevi
[20 Jan 2023 19:30] Daniel Valdez
Posted by developer:
 
No longer a bug. Verified using the latest version of Connector/NET, v8.0.32.