tursodatabase/turso · error · NotSupportedException

Turso does not support changing the active database.

Error message

Turso does not support changing the active database.

What it means

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.

Solutions

  1. Open a new TursoConnection with a different Data Source connection string instead of calling ChangeDatabase
  2. If generic code insists on calling it, catch NotSupportedException and fall back to a connection-per-database strategy
  3. Cache/pool connections keyed by database identifier to avoid reopen overhead

Example fix

// before
conn.ChangeDatabase("otherdb"); // always throws NotSupportedException

// after
using var other = new TursoConnection("Data Source=file:other.db");
other.Open();
Defensive patterns

Strategy: try-catch

Try / catch

try { conn.ChangeDatabase(name); }
catch (NotSupportedException)
{
    // fall back: open a dedicated connection per database
}

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of tursodatabase/turso@6c72522679 (2026-08-20). Data as JSON: /api/errors/993cc05fb08ea586. Report an issue: GitHub.

Appendix: source

Thrown at bindings/dotnet/src/Turso.Data/TursoConnection.cs:211

    }

    public Task SyncAsync(CancellationToken cancellationToken = default)
    {
        ObjectDisposedException.ThrowIf(_disposed, this);
        if (cancellationToken.IsCancellationRequested)
            return Task.FromCanceled(cancellationToken);
        if (State != ConnectionState.Open)
            throw new InvalidOperationException("Turso database is closed.");
        if (!_connectionOptions.IsReplica)
            throw new NotSupportedException("Sync requires an embedded replica connection.");

        return (_syncDatabase ?? throw new InvalidOperationException("The embedded replica is not initialized."))
            .PullAsync(cancellationToken);
    }

    public override void ChangeDatabase(string databaseName)
    {
        throw new NotSupportedException("Turso does not support changing the active database.");
    }

    internal int DefaultTimeout => _connectionOptions.DefaultTimeout;

    internal bool IsRemote => _remoteClient is not null;

    internal bool ReadUncommitted
    {
        get => _readUncommitted;
        set => _readUncommitted = value;
    }

    internal TursoDatabaseHandle Turso => _turso ?? throw new InvalidOperationException("Turso database is closed.");

    internal TursoSyncDatabase? SyncDatabase => _syncDatabase;

    public TursoAutomaticSyncStatus AutomaticSyncStatus =>
        Volatile.Read(ref _automaticSyncCoordinator)?.Status ?? Volatile.Read(ref _automaticSyncStatus);

View on GitHub (pinned to 6c72522679)