{"record":{"id":"fdbcb01af3bfdecf","repo":"tursodatabase/turso","slug":"sqlite-facade-batches-are-available-only-for-direc","errorCode":null,"errorMessage":"SQLite facade batches are available only for direct remote or embedded replica connections.","messagePattern":"SQLite facade batches are available only for direct remote or embedded replica connections\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteBatch.cs","lineNumber":369,"sourceCode":"            }\n\n            return new BatchState(managedBatch, statements, managedCommands, mappings);\n        }\n        catch\n        {\n            managedBatch.Dispose();\n            throw;\n        }\n    }\n\n    private SqliteConnection ValidateBatch()\n    {\n        var connection = _connection\n                         ?? throw new InvalidOperationException(\n                             \"Connection must be set before executing a batch.\");\n        if (!connection.IsManagedConnection)\n        {\n            throw new NotSupportedException(\n                \"SQLite facade batches are available only for direct remote or embedded replica connections.\");\n        }\n        if (connection.State != ConnectionState.Open)\n            throw new InvalidOperationException(Properties.Resources.CallRequiresOpenConnection(\"ExecuteBatch\"));\n        if (_transaction is { IsCompleted: true })\n            throw new InvalidOperationException(Properties.Resources.TransactionCompleted);\n        if (_transaction is not null && !ReferenceEquals(_transaction.Connection, connection))\n            throw new InvalidOperationException(Properties.Resources.TransactionConnectionMismatch);\n        if (connection.Transaction is not null\n            && !ReferenceEquals(_transaction, connection.Transaction))\n        {\n            throw new InvalidOperationException(Properties.Resources.TransactionRequired);\n        }\n        if (_batchCommands.Count == 0)\n            throw new InvalidOperationException(\"Batch must contain at least one command.\");\n\n        return connection;\n    }","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data.Sqlite/SqliteBatch.cs#L351-L387","documentation":"SQLite facade batches are only implemented for managed connections (direct remote or embedded replica connections). ValidateBatch checks connection.IsManagedConnection and throws NotSupportedException for any other connection kind, since the managed batch executor path does not exist for them.","triggerScenarios":"Using SqliteBatch with a plain embedded/local (non-managed) SqliteConnection that doesn't route through the managed remote/replica machinery, then executing the batch.","commonSituations":"Assuming SqliteBatch works for every Turso connection type; local embedded file databases where SqliteBatch is unsupported; switching a connection factory from local to remote without updating batch usage.","solutions":["Open the connection as a direct remote or embedded replica (managed) connection to use SqliteBatch","For local/embedded connections, execute statements with individual SqliteCommand calls or DbBatch alternatives supported by that path","Check connection.IsManagedConnection before choosing SqliteBatch"],"exampleFix":"// before\nvar localConn = new SqliteConnection(\"Data Source=local.db\");\nvar batch = new SqliteBatch { Connection = localConn }; // NotSupportedException\n// after\nvar remoteConn = SqliteConnection.CreateRemoteOrReplica(...); // managed connection\nvar batch = new SqliteBatch { Connection = remoteConn };","handlingStrategy":"validation","validationCode":"if (!connection.IsManagedConnection)\n    throw new NotSupportedException(\"SqliteBatch requires a direct remote or embedded replica connection\");","typeGuard":"static bool SupportsBatches(SqliteConnection c) => c.IsManagedConnection;","tryCatchPattern":"try { await batch.ExecuteReaderAsync(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"SQLite facade batches\")) { /* fall back to individual SqliteCommand execution */ }","preventionTips":["Only use SqliteBatch with direct remote or embedded replica connections","For local embedded file connections, execute commands individually","Check IsManagedConnection in helper code before choosing the batch API"],"tags":["dotnet","batch","connection","unsupported"],"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"}