Search code examples
c#mysqlado.netodbc

Simple stored procedure command failed after upgrade to MySQL ODBC connector 8.1


I've written a simple test application that calls a MySql stored procedure with parameters and populates a DataTable with the results.

It works without any issues when I have the MySQL ODBC 8.0 UNICODE Driver installed and specified in the query string. When I update the driver to 8.1 and change the connection string to use 8.1, the command fails with the following error:

ERROR [42000] [MySQL][ODBC 8.1(w) Driver][mysqld-8.0.34-commercial]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '{ call GetDashboardData(?, ?) }' at line 1'

Here is the code for the application, the only thing I change after upgrading the Connector driver is changing 8.0 to 8.1 in the connection string (and this connects to the database successfully)

    static void Main(string[] args)
    {
        var connection = new OdbcConnection("Driver={MySQL ODBC 8.1 UNICODE Driver}; Server=localhost; Database=theDatabase; Uid=theUser; Pwd=thePassword; ");
        
        connection.Open();
        OdbcCommand command = new OdbcCommand("{ call GetDashboardData(?, ?) }", connection);
        command.CommandType = CommandType.StoredProcedure;
        var param1 = command.CreateParameter();
        param1.ParameterName = "timePeriodHours";
        param1.Direction = ParameterDirection.Input;
        param1.Value = 24;
        param1.DbType = DbType.Int32;
        command.Parameters.Add(param1);

        var param2 = command.CreateParameter();
        param2.ParameterName = "IdList";
        param2.Direction = ParameterDirection.Input;
        param2.Value = "000";
        param2.DbType = DbType.String;
        command.Parameters.Add(param2);

        DataTable table = new DataTable();
        OdbcDataAdapter adapter = new OdbcDataAdapter(command);
        adapter.Fill(table);
        Console.WriteLine(table.Rows.Count);
    }

I don't see any mention of anything that could have changed between these versions that could affect this. Any help would be greatly appreciated

EDIT

If I create a stored procedure without parameters and set the command text to:

{ call GetDashboardData() }

it works. The issue only occurs when attempting to use parameters


Solution

  • Turns out it's a bug with the 8.1 MySql connector: https://bugs.mysql.com/bug.php?id=112285