{"record":{"id":"1c1e183b871d0aa9","repo":"tursodatabase/turso","slug":"sqlite-facade-batches-are-available-only-for-direc-1c1e18","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/SqliteConnection.cs","lineNumber":505,"sourceCode":"        if (destination.State != ConnectionState.Open)\n            destination.Open();\n\n        foreach (var createSql in GetSchemaSql())\n            destination.ExecuteNonQuery(createSql);\n\n        foreach (var tableName in GetUserTableNames())\n            CopyTableRows(destination, tableName);\n    }\n\n    public new virtual SqliteCommand CreateCommand() => new(this) { Transaction = Transaction };\n\n    protected override DbCommand CreateDbCommand() => CreateCommand();\n\n    protected override DbBatch CreateDbBatch()\n    {\n        if (_managedConnection is null)\n        {\n            throw new NotSupportedException(\n                \"SQLite facade batches are available only for direct remote or embedded replica connections.\");\n        }\n\n        return new SqliteBatch(this);\n    }\n\n    protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel)\n        => BeginTransaction(isolationLevel);\n\n    protected override ValueTask<DbTransaction> BeginDbTransactionAsync(\n        IsolationLevel isolationLevel,\n        CancellationToken cancellationToken)\n    {\n        cancellationToken.ThrowIfCancellationRequested();\n        return ValueTask.FromResult<DbTransaction>(BeginTransaction(isolationLevel));\n    }\n\n    protected override void Dispose(bool disposing)","sourceCodeStart":487,"sourceCodeEnd":523,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs#L487-L523","documentation":"This NotSupportedException is thrown by CreateDbBatch (the ADO.NET DbProviderFactory hook behind CreateBatch) when the SqliteConnection is not backed by the managed Turso connection. Batching through the SQLite facade relies on managed statement execution, which only direct remote and embedded replica connections provide.","triggerScenarios":"Calling conn.CreateBatch() (or letting DbBatch-based code paths invoke CreateDbBatch) on a SqliteConnection created from a plain local connection string (_managedConnection is null).","commonSituations":"Generic ADO.NET code that uses DbBatch everywhere now that .NET exposes it, run against local SQLite connections; factory-based data access layers unaware the backend differs per connection type.","solutions":["Use a managed Turso connection (direct remote or embedded replica) when you need DbBatch support","For local connections, execute statements as individual DbCommands instead of a DbBatch","Guard with conn.IsManagedConnection before calling CreateBatch and fall back to per-statement commands"],"exampleFix":"// before\nusing var batch = localConn.CreateBatch(); // throws\n\n// after\nif (localConn.IsManagedConnection)\n{\n    using var batch = localConn.CreateBatch();\n}\nelse\n{\n    foreach (var sql in statements) { /* execute individual commands */ }\n}","handlingStrategy":"fallback","validationCode":"if (!conn.IsManagedConnection) return ExecuteSequentially(conn, statements);","typeGuard":"DbBatch? TryCreateBatch(SqliteConnection c) => c.IsManagedConnection ? c.CreateBatch() : null;","tryCatchPattern":"try { return conn.CreateBatch(); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"facade batches\"))\n{\n    return null; // fall back to commands\n}","preventionTips":["Only rely on DbBatch behind managed Turso connections"],"tags":["dotnet","batch","remote-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"}