Skip to content

Issue with ExecuteReaderAsync on MySQL #1277

@walkindude

Description

@walkindude

Dapper version: 1.60.6
Target framework version: .NET 4.7
MySQL version: 5.6.22
MySql.Data version: 8.0.16

Code:

    public async Task<DataTable> GetDataTable(string sql, object parameters = null)
    {
        using (var conn = await GetConnection())
        using (var reader = conn.ExecuteReader(sql, parameters))
        {
            var table = new DataTable();
            table.Load(reader);
            return table;
        }
    }

(I'm using Dapper just to take advantage of its parameter handling, since it's so well designed).

With the same simple SELECT, the code above works as intended.

The code below, however, unless I'm doing something horribly wrong or stupid, does not:

    public async Task<DataTable> GetDataTable(string sql, object parameters = null)
    {
        using (var conn = await GetConnection())
        using (var reader = await conn.ExecuteReaderAsync(sql, parameters))
        {
            var table = new DataTable();
            table.Load(reader);
            return table;
        }
    }

The only difference is that in the latter I'm using ExecuteReaderAsync instead of ExecuteReader.

The DataTable that gets returned is completely empty: no columns, no rows, no nothing. I can't quite figure out why. Using the non-async version, as I said, works as expected.

Right now I can't try this on either Postgres or SQL Server or even a more recent version of MySql, so I can't tell whether it happens with other database engines as well.

Using the non-async version is no big deal, I'm doing this for a tiny internal utility and it's not a deal breaker, I just thought I would point this out.

EDIT: I'm adding a screenshot of the debugger with the cursor hovering over the DataReader just in case it's helpful.

Debugger

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions