{"record":{"id":"d11c4137e090245e","repo":"tursodatabase/turso","slug":"turso-batch-execution-is-currently-supported-only","errorCode":null,"errorMessage":"Turso batch execution is currently supported only for remote connections.","messagePattern":"Turso batch execution is currently supported only for remote connections\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoConnection.cs","lineNumber":159,"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 is currently supported only for remote connections.\");\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":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/tursodatabase/turso/blob/c1e59287258d99b309e362a63f48822256e2f65f/bindings/dotnet/src/Turso.Data/TursoConnection.cs#L141-L177","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)."],"exampleFix":"// before\nusing var conn = new TursoConnection(\"Data Source=app.db\");\nconn.Open();\nusing var batch = conn.CreateBatch(); // local conn -> throws NotSupportedException\n\n// after\nusing var conn = new TursoConnection(\"Data Source=libsql://my-db.turso.io;Auth Token=...\");\nconn.Open();\nusing var batch = conn.CreateBatch(); // remote -> supported","handlingStrategy":"fallback","validationCode":"if (!conn.CanCreateBatch)\n    throw new NotSupportedException(\"DbBatch requires a non-replica remote connection string.\");","typeGuard":"static bool SupportsBatch(TursoConnection c) => c.CanCreateBatch;","tryCatchPattern":"try\n{\n    batch = conn.CreateBatch();\n}\ncatch (NotSupportedException)\n{\n    // Local/replica connection: execute statements one by one instead.\n    foreach (var sql in statements)\n    {\n        using var c = conn.CreateCommand();\n        c.CommandText = sql;\n        c.ExecuteNonQuery();\n    }\n}","preventionTips":["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."],"tags":["dotnet","ado-net","tursodb","batch","remote","local-database","replica"],"backgroundTag":"feature-requires-remote-connection","analyzedSha":"c1e59287258d99b309e362a63f48822256e2f65f","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}