tursodatabase/turso · error · NotSupportedException

Turso batch execution requires a direct remote or embedded r

Error message

Turso batch execution requires a direct remote or embedded replica connection.

What it means

CreateDbBatch (the ADO.NET DbBatch factory) checks CanCreateBatch; when the connection is not a direct remote or embedded replica connection it refuses to create a TursoBatch, throwing NotSupportedException. Batching is only implemented for those connection kinds.

Source

Thrown at bindings/dotnet/src/Turso.Data/TursoConnection.cs:177

    protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)
    {
        if (_turso is null && _remoteClient is null)
        {
            throw new InvalidOperationException("Turso database is closed.");
        }

        return new TursoTransaction(this, isolationLevel);
    }

    protected override DbCommand CreateDbCommand()
    {
        return new TursoCommand(this);
    }

    protected override DbBatch CreateDbBatch()
    {
        if (!CanCreateBatch)
            throw new NotSupportedException("Turso batch execution requires a direct remote or embedded replica connection.");

        return new TursoBatch(this);
    }

    public int ExecuteNonQuery(string sql)
    {
        using var command = CreateCommand();
        command.CommandText = sql;

        return command.ExecuteNonQuery();
    }

    public void Sync()
    {
        SyncAsync(CancellationToken.None).GetAwaiter().GetResult();
    }

    public Task SyncAsync(CancellationToken cancellationToken = default)

View on GitHub (pinned to 6c72522679)

Solutions

  1. Configure the connection as a direct remote or embedded replica before calling CreateBatch.
  2. Check CanCreateBatch first and fall back to individual commands in a transaction when false.
  3. Catch NotSupportedException and route to a non-batch execution path.

Example fix

// before
using var batch = conn.CreateBatch(); // throws on plain local conn
// after
if (!conn.CanCreateBatch)
    foreach (var cmd in commands) await cmd.ExecuteNonQueryAsync();
else
    using (var batch = conn.CreateBatch()) { ... }
Defensive patterns

Strategy: fallback

Validate before calling

if (!conn.CanCreateBatch) { /* use sequential commands */ }

Try / catch

try { using var batch = conn.CreateBatch(); ... }
catch (NotSupportedException) { foreach (var cmd in commands) await cmd.ExecuteNonQueryAsync(); }

Prevention

When it happens

Trigger: Calling connection.CreateBatch() (or DbProviderFactory batching) on a TursoConnection that is a plain local connection or otherwise lacks sync/remote capability.

Common situations: Generic ADO.NET code that calls CreateBatch unconditionally for any DbConnection; migrating local-file apps to Turso and switching to the batch API without changing connection configuration.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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