tursodatabase/turso · error · SqliteException

1

1

Error message

SQLite Error 1: 'Managed batch returned more than {state.Statements.Count} results.'.

What it means

The managed batch executor drives the reader with NextResultAsync once per parsed statement. This invariant error fires when the underlying connection produced more result sets than statements that were parsed from the batch CommandText, indicating the engine returned extra results for the submitted script.

Source

Thrown at bindings/dotnet/src/Turso.Data.Sqlite/SqliteBatch.cs:230

                closeCallback);
        }

        await using (state.Batch)
        {
            await WaitForOpenReaderAsync(state.Statements, cancellationToken).ConfigureAwait(false);
            _activeBatch = state.Batch;
            try
            {
                await using var reader = await state.Batch
                    .ExecuteReaderAsync(behavior & ~CommandBehavior.CloseConnection, cancellationToken)
                    .ConfigureAwait(false);
                var results = new List<ManagedSqliteResult>(state.Statements.Count);
                var statementIndex = 0;
                do
                {
                    if (statementIndex >= state.Statements.Count)
                    {
                        throw new SqliteException(
                            Properties.Resources.SqliteNativeError(
                                1,
                                $"Managed batch returned more than {state.Statements.Count} results."),
                            1);
                    }

                    var statement = state.Statements[statementIndex];
                    var result = await SqliteCommand
                        .BufferManagedResultAsync(reader, statement.Sql, cancellationToken)
                        .ConfigureAwait(false);
                    results.Add(result with
                    {
                        RecordsAffected = state.ManagedCommands[statementIndex].RecordsAffected,
                    });
                    statementIndex++;
                }
                while (await reader.NextResultAsync(cancellationToken).ConfigureAwait(false));

View on GitHub (pinned to 6c72522679)

Solutions

  1. Update the Turso.Data.Sqlite package and server/driver to matching versions
  2. Reduce the batch to individual SqliteCommand executions to isolate which statement produces the extra result
  3. Reproduce and report with the exact CommandText; likely a parser/engine mismatch bug
Defensive patterns

Strategy: try-catch

Try / catch

try { await batch.ExecuteReaderAsync(); }
catch (SqliteException ex) when (ex.SqliteErrorCode == 1 && ex.Message.Contains("more than")) {
    // engine/parser statement-count mismatch: log CommandText, retry per-statement
}

Prevention

When it happens

Trigger: Calling ExecuteReader/ExecuteDbDataReaderAsync on a SqliteBatch whose managed connection emits more result streams than the statements in state.Statements.Count — an engine/driver protocol mismatch, e.g. a statement the parser split differently than the server executed, or a driver bug.

Common situations: Rare internal-inconsistency case; typically hit after a driver version upgrade, when the managed statement parser and the remote/embedded replica connection disagree on statement count, or with unusual SQL (triggers, RETURNING, multi-result pragmas).

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-09-06). Data as JSON: /api/errors/f2421b72678e5009. Report an issue: GitHub.