{"record":{"id":"8204889a5dabc91d","repo":"tursodatabase/turso","slug":"changing-databases-is-not-supported","errorCode":null,"errorMessage":"Changing databases is not supported.","messagePattern":"Changing databases is not supported\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs","lineNumber":266,"sourceCode":"        _recursiveTriggers = false;\n        _readUncommitted = false;\n        if (_sharedMemoryPath is not null)\n        {\n            ReleaseSharedMemoryFile(_sharedMemoryPath);\n            _sharedMemoryPath = null;\n        }\n        OnStateChange(new StateChangeEventArgs(originalState, State));\n    }\n\n    public override void ChangeDatabase(string databaseName)\n    {\n        if (_managedConnection is not null)\n        {\n            _managedConnection.ChangeDatabase(databaseName);\n            return;\n        }\n\n        throw new NotSupportedException(\"Changing databases is not supported.\");\n    }\n\n    public void Sync()\n    {\n        GetManagedConnectionForSync().Sync();\n    }\n\n    public Task SyncAsync(CancellationToken cancellationToken = default)\n    {\n        return GetManagedConnectionForSync().SyncAsync(cancellationToken);\n    }\n\n    public override DataTable GetSchema()\n        => GetSchema(DbMetaDataCollectionNames.MetaDataCollections, null);\n\n    public override DataTable GetSchema(string collectionName)\n        => GetSchema(collectionName, null);\n","sourceCodeStart":248,"sourceCodeEnd":284,"githubUrl":"https://github.com/tursodatabase/turso/blob/6c7252267988c76e632af00a671e4b9788dfae13/bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs#L248-L284","documentation":"DbConnection.ChangeDatabase is hard-coded to throw NotSupportedException: SQLite/Turso is a single-database-per-connection engine (one file per connection, selected at open time), so the ADO.NET notion of switching the current database has no equivalent. Any call fails regardless of the name passed. The provider implements the API only to satisfy the base contract.","triggerScenarios":"Calling conn.ChangeDatabase(\"other\") directly; generic ADO.NET frameworks, ORMs, or reporting tools that switch databases via ChangeDatabase after connecting; code ported from SqlClient where ChangeDatabase selects an initial catalog.","commonSituations":"Adapters written against DbConnection that probe capabilities by switching catalogs; migration from SQL Server/MySQL codepaths that 'use db' per request; connection managers that try to reuse one connection for multiple databases.","solutions":["Open a separate SqliteConnection per database file and route operations to the right connection.","If you need cross-database queries, use SQL 'ATTACH DATABASE \"other.db\" AS other;' and reference other.table_name.","Remove ChangeDatabase from generic code paths when the provider is SQLite/Turso (guard by ADO.NET provider name)."],"exampleFix":"// before\nusing var conn = new SqliteConnection(\"Data Source=main.db\");\nconn.Open();\nconn.ChangeDatabase(\"other.db\"); // throws: Changing databases is not supported\n\n// after\nusing var main = new SqliteConnection(\"Data Source=main.db\");\nmain.Open();\nusing var other = new SqliteConnection(\"Data Source=other.db\");\nother.Open();\n// or: main.ExecuteNonQuery(\"ATTACH DATABASE 'other.db' AS other;\");","handlingStrategy":"fallback","validationCode":"static DbConnection ConnectTo(string connectionString)\n{\n    var conn = new SqliteConnection(connectionString);\n    conn.Open();\n    return conn; // one connection per database file; no ChangeDatabase\n}","typeGuard":null,"tryCatchPattern":"null","preventionTips":["In provider-agnostic code, branch on connection type before calling ChangeDatabase.","Use ATTACH DATABASE when cross-database joins are needed on a single connection.","Map 'database' concept to connection-string DataSource for SQLite/Turso."],"tags":["ado-net","sqlite","turso","unsupported-feature","connection-lifecycle"],"backgroundTag":"unsupported-provider-feature","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"}