Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqliteCommand.ExecuteReaderAsync with CommandBehavior.CloseConnection appears broken #14674

Closed
tdinucci opened this issue Feb 12, 2019 · 3 comments

Comments

@tdinucci
Copy link
Member

tdinucci commented Feb 12, 2019

Edit: This issue is present in v2.2.1 but not v2.0.0

When creating an SqliteDataReader using CommandBehavior.CloseConnection from an SqliteCommand which is disposed the reader and connection are closed prematurely.

Steps to reproduce

using (var cmd = GetDbCommand(statement))
{
     if (cmd.Connection.State != ConnectionState.Open)
         cmd.Connection.Open();

    cmd.CommandType = statement.Type;
    if (statement.Parameters != null)
    {
        // AddRange(...) seems to have a bug in SqliteCommand
        foreach (var parameter in statement.Parameters)
            cmd.Parameters.Add(parameter);
     }
    return await cmd.ExecuteReaderAsync(CommandBehavior.CloseConnection).ConfigureAwait(false);
}

Further technical details

Operating system: Ubuntu 18.04

From a very quick look it seems that the call shown below to this.DataReader.Dispose() on SqliteCommand is being called and the CommandBehavior is ignored.

private void DisposePreparedStatements(bool disposing = true)
{
    if (disposing && this.DataReader != null)
    {
        this.DataReader.Dispose();
        this.DataReader = (SqliteDataReader) null;
    }
    ...
}
@ajcvickers
Copy link
Member

@bricelam to investigate for patch.

@bricelam
Copy link
Contributor

Duplicate of aspnet/Microsoft.Data.Sqlite#484

BUT the architecture I have in mind for #14044 will remove the need to dispose SqliteCommand objects. It will also allow them to be disposed while their SqliteDataReader is open.

@bricelam
Copy link
Contributor

The workaround for your specific case is to not dispose the command object. It will get disposed when the connection is closed.

@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants