{"record":{"id":"993cc05fb08ea586","repo":"tursodatabase/turso","slug":"turso-does-not-support-changing-the-active-databas","errorCode":null,"errorMessage":"Turso does not support changing the active database.","messagePattern":"Turso does not support changing the active database\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data/TursoConnection.cs","lineNumber":167,"sourceCode":"        SyncAsync(CancellationToken.None).GetAwaiter().GetResult();\n    }\n\n    public Task SyncAsync(CancellationToken cancellationToken = default)\n    {\n        ObjectDisposedException.ThrowIf(_disposed, this);\n        if (cancellationToken.IsCancellationRequested)\n            return Task.FromCanceled(cancellationToken);\n        if (State != ConnectionState.Open)\n            throw new InvalidOperationException(\"Turso database is closed.\");\n        if (!_connectionOptions.IsReplica)\n            throw new NotSupportedException(\"Sync requires an embedded replica connection.\");\n\n        throw new NotSupportedException(\"Embedded replica sync is not supported yet by the .NET provider.\");\n    }\n\n    public override void ChangeDatabase(string databaseName)\n    {\n        throw new NotSupportedException(\"Turso does not support changing the active database.\");\n    }\n\n    internal int DefaultTimeout => _connectionOptions.DefaultTimeout;\n\n    internal bool IsRemote => _remoteClient is not null;\n\n    internal bool ReadUncommitted\n    {\n        get => _readUncommitted;\n        set => _readUncommitted = value;\n    }\n\n    internal TursoDatabaseHandle Turso => _turso ?? throw new InvalidOperationException(\"Turso database is closed.\");\n\n    internal async Task<RemoteStatementResult> ExecuteRemoteAsync(\n        string sql,\n        TursoParameterCollection parameters,\n        bool wantRows,","sourceCodeStart":149,"sourceCodeEnd":185,"githubUrl":"https://github.com/tursodatabase/turso/blob/244cde92a7df7f9b8b8b7a4075c35a12977e303e/bindings/dotnet/src/Turso.Data/TursoConnection.cs#L149-L185","documentation":"ChangeDatabase is an abstract DbConnection member every ADO.NET provider must implement; TursoConnection always throws NotSupportedException because one connection is bound to exactly one database for its lifetime (the underlying handle is opened per Data Source). There is no code path that succeeds.","triggerScenarios":"Calling conn.ChangeDatabase(\"otherdb\") at any time, open or closed; generic middleware (migration runners, test harnesses, ORM tooling) that calls ChangeDatabase when it wants to switch catalogs, a pattern inherited from SqlClient/MySqlConnector usage.","commonSituations":"Adapters written for SQL Server or MySQL where per-connection database switching is routine; multi-tenant code that reuses one pooled connection across tenants; tooling that probes multiple databases through one connection.","solutions":["Open a new TursoConnection with a different Data Source connection string instead of calling ChangeDatabase","If generic code insists on calling it, catch NotSupportedException and fall back to a connection-per-database strategy","Cache/pool connections keyed by database identifier to avoid reopen overhead"],"exampleFix":"// before\nconn.ChangeDatabase(\"otherdb\"); // always throws NotSupportedException\n\n// after\nusing var other = new TursoConnection(\"Data Source=file:other.db\");\nother.Open();","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { conn.ChangeDatabase(name); }\ncatch (NotSupportedException)\n{\n    // fall back: open a dedicated connection per database\n}","preventionTips":["Design for connection-per-database instead of connection-per-server","Flag TursoConnection as non-switchable in adapter capability matrices","Key a connection pool by database name up front"],"tags":["csharp","dotnet","turso","ado-net","not-supported"],"backgroundTag":"changing-database-unsupported","analyzedSha":"244cde92a7df7f9b8b8b7a4075c35a12977e303e","analyzedAt":"2026-08-20T07:02:18.389Z","schemaVersion":2},"datasetVersion":"2026-08-21T13:17:26.733Z"}