tursodatabase/turso · error · NotSupportedException
Turso batch execution is currently supported only for remote
Error message
Turso batch execution is currently supported only for remote connections.
What it means
CreateDbBatch throws NotSupportedException when CanCreateBatch is false (TursoConnection.cs:131-136). CanCreateBatch is true only when the connection string's Data Source is a remote URL (libsql/http/https/ws/wss scheme) and not a replica, because DbBatch is implemented over the remote batch protocol; embedded/local file connections (and replica mode with a ReplicaPath) cannot run batches.
Source
Thrown at bindings/dotnet/src/Turso.Data/TursoConnection.cs:159
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 is currently supported only for remote connections.");
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 c1e5928725)
Solutions
- Use a remote connection string for batch workloads: "Data Source=libsql://your-db.turso.io;Auth Token=...".
- On local connections, execute the statements sequentially with TursoCommand instead of DbBatch.
- Branch on conn.CanCreateBatch before CreateBatch and fall back to per-statement execution (see defense snippet).
Example fix
// before
using var conn = new TursoConnection("Data Source=app.db");
conn.Open();
using var batch = conn.CreateBatch(); // local conn -> throws NotSupportedException
// after
using var conn = new TursoConnection("Data Source=libsql://my-db.turso.io;Auth Token=...");
conn.Open();
using var batch = conn.CreateBatch(); // remote -> supported Defensive patterns
Strategy: fallback
Validate before calling
if (!conn.CanCreateBatch)
throw new NotSupportedException("DbBatch requires a non-replica remote connection string."); Type guard
static bool SupportsBatch(TursoConnection c) => c.CanCreateBatch;
Try / catch
try
{
batch = conn.CreateBatch();
}
catch (NotSupportedException)
{
// Local/replica connection: execute statements one by one instead.
foreach (var sql in statements)
{
using var c = conn.CreateCommand();
c.CommandText = sql;
c.ExecuteNonQuery();
}
} Prevention
- Check conn.CanCreateBatch before building DbBatch pipelines.
- Keep the Data Source a remote libsql:// URL (without ReplicaPath) for batch workloads.
- Maintain a sequential-execution fallback for local file and replica configurations.
When it happens
Trigger: new TursoConnection("Data Source=app.db").CreateBatch(); — a local file Data Source. Also fires for a libsql:// URL that additionally specifies a ReplicaPath, since replicas disable CanCreateBatch too.
Common situations: Developing against a local file database while production uses remote (or the reverse); enabling replica mode in the connection string; generic DAL/EF-style code that unconditionally uses DbBatch for bulk work.
Related errors
- TursoBatchCommand only supports CommandType.Text.
- Batch command must be a TursoBatchCommand.
- CommandText must be set before executing a command.
- TursoCommand only supports CommandType.Text.
- Connection must be a TursoConnection.
AI-assisted analysis of tursodatabase/turso@c1e5928725 (2026-08-20).
Data as JSON: /api/errors/d11c4137e090245e.
Report an issue: GitHub.