{"record":{"id":"ca3717198c882dc4","repo":"tursodatabase/turso","slug":"turso-batch-execution-requires-a-direct-remote-or-ca3717","errorCode":null,"errorMessage":"Turso batch execution requires a direct remote or embedded replica connection.","messagePattern":"Turso batch execution requires a direct remote or embedded replica connection\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoConnection.cs","lineNumber":177,"sourceCode":"    protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)\n    {\n        if (_turso is null && _remoteClient is null)\n        {\n            throw new InvalidOperationException(\"Turso database is closed.\");\n        }\n\n        return new TursoTransaction(this, isolationLevel);\n    }\n\n    protected override DbCommand CreateDbCommand()\n    {\n        return new TursoCommand(this);\n    }\n\n    protected override DbBatch CreateDbBatch()\n    {\n        if (!CanCreateBatch)\n            throw new NotSupportedException(\"Turso batch execution requires a direct remote or embedded replica connection.\");\n\n        return new TursoBatch(this);\n    }\n\n    public int ExecuteNonQuery(string sql)\n    {\n        using var command = CreateCommand();\n        command.CommandText = sql;\n\n        return command.ExecuteNonQuery();\n    }\n\n    public void Sync()\n    {\n        SyncAsync(CancellationToken.None).GetAwaiter().GetResult();\n    }\n\n    public Task SyncAsync(CancellationToken cancellationToken = default)","sourceCodeStart":159,"sourceCodeEnd":195,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data/TursoConnection.cs#L159-L195","documentation":"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.","triggerScenarios":"Calling connection.CreateBatch() (or DbProviderFactory batching) on a TursoConnection that is a plain local connection or otherwise lacks sync/remote capability.","commonSituations":"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.","solutions":["Configure the connection as a direct remote or embedded replica before calling CreateBatch.","Check CanCreateBatch first and fall back to individual commands in a transaction when false.","Catch NotSupportedException and route to a non-batch execution path."],"exampleFix":"// before\nusing var batch = conn.CreateBatch(); // throws on plain local conn\n// after\nif (!conn.CanCreateBatch)\n    foreach (var cmd in commands) await cmd.ExecuteNonQueryAsync();\nelse\n    using (var batch = conn.CreateBatch()) { ... }","handlingStrategy":"fallback","validationCode":"if (!conn.CanCreateBatch) { /* use sequential commands */ }","typeGuard":null,"tryCatchPattern":"try { using var batch = conn.CreateBatch(); ... }\ncatch (NotSupportedException) { foreach (var cmd in commands) await cmd.ExecuteNonQueryAsync(); }","preventionTips":["Check CanCreateBatch before batching.","Use one connection factory that always configures remote/replica mode for batch-heavy code paths.","Document that TursoBatch requires direct remote or embedded replica connections."],"tags":["csharp","dotnet","batch","connection"],"backgroundTag":"unsupported-operation","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-09-06T07:15:26.990Z","contentChangedAt":"2026-09-06T07:15:26.990Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}