{"record":{"id":"43b310b9011878c8","repo":"tursodatabase/turso","slug":"the-connection-does-not-use-the-managed-turso-back","errorCode":null,"errorMessage":"The connection does not use the managed Turso backend.","messagePattern":"The connection does not use the managed Turso backend\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs","lineNumber":125,"sourceCode":"    public bool IsDirectRemote => _connectionOptions.IsDirectRemote;\n\n    public bool IsRemote => _connectionOptions.IsRemote;\n\n    public bool IsReplica => _connectionOptions.IsReplica;\n\n    public bool IsManaged => IsRemote;\n\n    public TursoSyncDatabase? SyncDatabase => _managedConnection?.SyncDatabase;\n\n    internal bool IsSharedCache => _connectionOptions.Cache == SqliteCacheMode.Shared;\n\n    internal bool IsManagedConnection => _managedConnection is not null;\n\n    private bool HasNativeCallbackHandle =>\n        _database is not null || IsReplica && State == ConnectionState.Open;\n\n    internal TursoConnection ManagedConnection => _managedConnection\n        ?? throw new InvalidOperationException(\"The connection does not use the managed Turso backend.\");\n\n    internal bool ReadUncommitted\n    {\n        get => _readUncommitted;\n        set => _readUncommitted = value;\n    }\n\n    // The SQLite version Turso tracks (SQLITE_VERSION in core/dialect/sqlite.rs).\n    public override string ServerVersion => \"3.50.4\";\n\n    public override ConnectionState State => _managedConnection?.State\n        ?? (_database is null ? ConnectionState.Closed : ConnectionState.Open);\n\n    public override bool CanCreateBatch => _managedConnection?.CanCreateBatch == true;\n\n    protected override DbProviderFactory DbProviderFactory => SqliteFactory.Instance;\n\n    public override void Open()","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs#L107-L143","documentation":"This InvalidOperationException is thrown by the internal ManagedConnection property when accessed on a SqliteConnection whose _managedConnection field is null, i.e. a connection that is not backed by the managed Turso backend (native local connections and replicas without a managed wrapper).","triggerScenarios":"Invoking internal APIs that require the managed backend (e.g. managed statements, Turso handle access on non-replica wrappers, batch operations) on a SqliteConnection created purely from a local connection string.","commonSituations":"Internal/extension code calling ManagedConnection without first checking IsManagedConnection; tests or tooling mixing native and managed connection objects.","solutions":["Check conn.IsManagedConnection before accessing ManagedConnection","Use the wrapper constructor SqliteConnection(TursoConnection, bool) to obtain a managed-backed connection","Route local connections through the native code path instead of managed APIs"],"exampleFix":"// before\nvar turso = conn.ManagedConnection.Turso; // throws for local conns\n\n// after\nif (conn.IsManagedConnection)\n{\n    var turso = conn.ManagedConnection.Turso;\n}","handlingStrategy":"type-guard","validationCode":"if (!conn.IsManagedConnection) return UseNativePath(conn);","typeGuard":"bool IsManaged(SqliteConnection c) => c.IsManagedConnection;","tryCatchPattern":"try { UseManaged(conn.ManagedConnection); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"managed Turso backend\"))\n{\n    UseNativePath(conn);\n}","preventionTips":["Guard every managed-only internal call with IsManagedConnection"],"tags":["dotnet","connection","internal-api"],"backgroundTag":"invalid-state-transition","analyzedSha":"6c7252267988c76e632af00a671e4b9788dfae13","analyzedAt":"2026-09-06T07:15:26.990Z","contentChangedAt":"2026-09-06T07:15:26.990Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}