tursodatabase/turso · error · NotSupportedException

Changing databases is not supported.

Error message

Changing databases is not supported.

What it means

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.

Source

Thrown at bindings/dotnet/src/Turso.Data.Sqlite/SqliteConnection.cs:266

        _recursiveTriggers = false;
        _readUncommitted = false;
        if (_sharedMemoryPath is not null)
        {
            ReleaseSharedMemoryFile(_sharedMemoryPath);
            _sharedMemoryPath = null;
        }
        OnStateChange(new StateChangeEventArgs(originalState, State));
    }

    public override void ChangeDatabase(string databaseName)
    {
        if (_managedConnection is not null)
        {
            _managedConnection.ChangeDatabase(databaseName);
            return;
        }

        throw new NotSupportedException("Changing databases is not supported.");
    }

    public void Sync()
    {
        GetManagedConnectionForSync().Sync();
    }

    public Task SyncAsync(CancellationToken cancellationToken = default)
    {
        return GetManagedConnectionForSync().SyncAsync(cancellationToken);
    }

    public override DataTable GetSchema()
        => GetSchema(DbMetaDataCollectionNames.MetaDataCollections, null);

    public override DataTable GetSchema(string collectionName)
        => GetSchema(collectionName, null);

View on GitHub (pinned to 6c72522679)

Solutions

  1. Open a separate SqliteConnection per database file and route operations to the right connection.
  2. If you need cross-database queries, use SQL 'ATTACH DATABASE "other.db" AS other;' and reference other.table_name.
  3. Remove ChangeDatabase from generic code paths when the provider is SQLite/Turso (guard by ADO.NET provider name).

Example fix

// before
using var conn = new SqliteConnection("Data Source=main.db");
conn.Open();
conn.ChangeDatabase("other.db"); // throws: Changing databases is not supported

// after
using var main = new SqliteConnection("Data Source=main.db");
main.Open();
using var other = new SqliteConnection("Data Source=other.db");
other.Open();
// or: main.ExecuteNonQuery("ATTACH DATABASE 'other.db' AS other;");
Defensive patterns

Strategy: fallback

Validate before calling

static DbConnection ConnectTo(string connectionString)
{
    var conn = new SqliteConnection(connectionString);
    conn.Open();
    return conn; // one connection per database file; no ChangeDatabase
}

Try / catch

null

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-09-06). Data as JSON: /api/errors/8204889a5dabc91d. Report an issue: GitHub.