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

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

Closed
Pforzech opened this issue Jan 23, 2016 · 4 comments

Comments

@Pforzech
Copy link

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?

@mgravell
Copy link
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.

@NickCraver
Copy link
Member

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

@NickCraver
Copy link
Member

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

@NickCraver
Copy link
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
Projects
None yet
Development

No branches or pull requests

3 participants