{"record":{"id":"06ac688e45259c27","repo":"tursodatabase/turso","slug":"turso-batch-execution-requires-a-direct-remote-or","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/TursoBatch.cs","lineNumber":160,"sourceCode":"        return await CreateDataReaderAsync(results, behavior, cancellationToken).ConfigureAwait(false);\n    }\n\n    private async Task<IReadOnlyList<RemoteStatementResult>> ExecuteBatch(\n        bool wantRows,\n        CancellationToken cancellationToken)\n    {\n        cancellationToken.ThrowIfCancellationRequested();\n\n        var connection = ValidateBatch();\n        if (connection.IsRemote)\n        {\n            return await connection\n                .ExecuteRemoteBatchAsync(_batchCommands.AsReadOnly(), Timeout, wantRows, cancellationToken)\n                .ConfigureAwait(false);\n        }\n\n        if (connection.SyncDatabase is null)\n            throw new NotSupportedException(\"Turso batch execution requires a direct remote or embedded replica connection.\");\n\n        var results = new List<RemoteStatementResult>(_batchCommands.Count);\n        foreach (var batchCommand in _batchCommands.AsReadOnly())\n        {\n            cancellationToken.ThrowIfCancellationRequested();\n            using var command = new TursoCommand(connection)\n            {\n                CommandText = batchCommand.CommandText,\n                CommandTimeout = Timeout,\n                Transaction = _transaction,\n            };\n            foreach (TursoParameter parameter in batchCommand.Parameters)\n                command.Parameters.Add(parameter);\n\n            results.Add(wantRows\n                ? await BufferResultAsync(command, cancellationToken).ConfigureAwait(false)\n                : new RemoteStatementResult\n                {","sourceCodeStart":142,"sourceCodeEnd":178,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data/TursoBatch.cs#L142-L178","documentation":"ExecuteBatch's sync-database path only supports connections that are a direct remote connection or an embedded replica. If the connection's SyncDatabase is null (neither case), the batch cannot be executed and NotSupportedException is thrown.","triggerScenarios":"Calling TursoBatch.ExecuteNonQueryAsync/ExecuteReaderAsync (or the DbBatch API) on a TursoConnection that is neither a direct remote nor an embedded replica connection — e.g. a plain local file connection or one whose sync database was not configured.","commonSituations":"Configuring a connection without TursoConnectionOptions sync settings and then trying TursoBatch; running the same batch code against both sync-enabled and non-sync connections; forgetting to set up the embedded replica.","solutions":["Open the connection as a direct remote connection or embedded replica (configure TursoConnectionOptions with sync settings).","Check connection type before batching: fall back to sequential TursoCommand executions when SyncDatabase is null.","Catch NotSupportedException and surface a configuration error to the caller."],"exampleFix":"// before\nusing var conn = new TursoConnection(\"file:local.db\"); // no sync configured\nawait batch.ExecuteNonQueryAsync();\n// after\nvar conn = new TursoConnection(new TursoConnectionStringBuilder { RemoteUrl = \"...\", AuthToken = \"...\" }.ToString());\nawait conn.OpenAsync();\nawait batch.ExecuteNonQueryAsync();","handlingStrategy":"try-catch","validationCode":"if (connection.SyncDatabase is null)\n    throw new InvalidOperationException(\"Batches require a direct remote or embedded replica connection.\");","typeGuard":null,"tryCatchPattern":"try { await batch.ExecuteNonQueryAsync(ct); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Turso batch execution requires\"))\n{ /* fall back to sequential commands */ }","preventionTips":["Configure sync options (remote URL/replica path) whenever you plan to use TursoBatch.","Check connection.CanCreateBatch before CreateBatch/ExecuteBatch.","Keep a single connection-creation helper so sync settings aren't forgotten."],"tags":["csharp","dotnet","batch","sync","configuration"],"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"}