{"record":{"id":"6ceb631bf0573ca1","repo":"tursodatabase/turso","slug":"turso-database-is-closed","errorCode":null,"errorMessage":"Turso database is closed.","messagePattern":"Turso database is closed\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoConnection.cs","lineNumber":163,"sourceCode":"    protected override void Dispose(bool disposing)\n    {\n        try\n        {\n            if (disposing)\n                Close();\n        }\n        finally\n        {\n            _disposed = true;\n            base.Dispose(disposing);\n        }\n    }\n\n    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","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data/TursoConnection.cs#L145-L181","documentation":"BeginDbTransaction throws InvalidOperationException when the connection has neither a local database handle nor a remote client (TursoConnection.cs:117-122) — it was never opened, or was closed/disposed. Transactions attach to an active database session, so there is nothing to begin one on.","triggerScenarios":"var conn = new TursoConnection(cs); conn.BeginTransaction(); without calling Open; or BeginTransaction after Close/Dispose (e.g. outside a using scope that already ended).","commonSituations":"A refactor removed the conn.Open() call; assuming SqlClient-style implicit open via pooling (Turso requires explicit Open); connection held past its using block or disposed by DI and then reused.","solutions":["Call conn.Open() (or await conn.OpenAsync(ct)) before BeginTransaction.","Guard shared code: if (conn.State != ConnectionState.Open) throw a clear error or open first.","Audit connection lifetimes in DI so disposed connections are not handed to new work."],"exampleFix":"// before\nusing var conn = new TursoConnection(cs);\nusing var tx = conn.BeginTransaction(); // never opened -> throws\n\n// after\nusing var conn = new TursoConnection(cs);\nconn.Open();\nusing var tx = conn.BeginTransaction();","handlingStrategy":"validation","validationCode":"if (conn.State != ConnectionState.Open)\n    throw new InvalidOperationException(\"Open the TursoConnection before beginning a transaction.\");\n// or: await conn.OpenAsync(ct);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat Open as a mandatory step; Turso never auto-opens.","Keep BeginTransaction inside the same scope that owns the open connection.","Check State in generic transaction wrappers before delegating."],"tags":["dotnet","ado-net","tursodb","transaction","connection","lifecycle"],"backgroundTag":"connection-not-open","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-08-20T07:02:18.389Z","contentChangedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}