Skip to content

SqliteConnection.Query<T> throws exception "CommandBehavior 'SingleResult, SequentialAccess' is invalid" from Microsoft.Data.Sqlite.dll #441

Closed

Description

@Pforzech

Executing a simple query is throwing an exception. I'm creating a ASP.NET 5 / .NET Core 1.0 project using latest beta of Dapper.NET (1.50.0-beta7) with a SQLite db.

using Dapper;
using Microsoft.Data.Sqlite;

...

var connectionString = "Data Source=./db/test.db";

using (var connection = new SqliteConnection(connectionString))
{
    connection.Open();

    connection.Execute(@"
        CREATE TABLE IF NOT EXISTS [DinosaurTypes] (
            [Id] UUID NOT NULL PRIMARY KEY,
            [Name] NVARCHAR(200) NOT NULL
        )");

    connection.Execute(@"
        INSERT INTO [DinosaurTypes]
            (Id, Name)
        VALUES
            ('A1A38605-08D0-4695-A037-514A997FABF1', 'Stegosaurus')");

    // This throws a InvalidArgument exception.
    var results = connection.Query<DinosaurType>("SELECT * FROM [DinosaurTypes]");

        // This works of course without the mapping to a model.
    var command = new CommandDefinition("SELECT * FROM [DinosaurTypes]");

    using (var reader = connection.ExecuteReader(command, CommandBehavior.Default))
    {
        object[] values = new object[2];
        while (reader.Read())
        {
            reader.GetValues(values);
        }
    }
}

My project.json looks like:

{
  "version": "1.0.0-*",
  "compilationOptions": {
    "emitEntryPoint": true
  },

    "dependencies": {
        "Dapper": "1.50.0-beta7",
        "Microsoft.AspNet.Diagnostics": "1.0.0-rc1-final",
        "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
        "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
        "Microsoft.Data.Sqlite": "1.0.0-rc1-final",
        "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
        "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
    },

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel --server-urls http://0.0.0.0:5000"
  },

  "frameworks": {
    "dnx451": { },
    "dnxcore50": { }
  },

  "exclude": [
    "wwwroot",
    "node_modules"
  ],
  "publishExclude": [
    "**.user",
    "**.vspscc"
  ]
}

It appears Dapper wants to set CommandBehavior.SingleResult on the DataReader (for performance reasons?), but the SQLite adapter doesn't support that. Is there a fix planned for this, or am I missing something?

Activity

  1. mgravell commented on Jan 23, 2016

    @mgravell
    Member

    Is there a fix planned for this,

    This is the first I've heard of it; holy wow, that's a terrible thing for the SQLite adapter to do. If you can't support a suggested optimization, you (the adapter) should just carry on as normal - you shouldn't throw. That's really sucky, and IMO very definitely a bug in the SQLite adapter. I'll see if I can log it there. This would definitely break all recent dapper builds for SQLite. I'll investigate.

  2. NickCraver commented on Jan 26, 2016

    @NickCraver
    Member

    Issue created in the provider repo: aspnet/Microsoft.Data.Sqlite#220

  3. NickCraver commented on Jan 27, 2016

    @NickCraver
    Member

    I've submitted a pull request to hopefully fix this behavior soon: aspnet/Microsoft.Data.Sqlite#221

  4. NickCraver commented on May 20, 2018

    @NickCraver
    Member

    This is now fixed in the framework (Microsoft.Data.Sqlite). Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions