tursodatabase/turso · error · ArgumentException

Unknown collection: {collectionName}.

Error message

Unknown collection: {collectionName}.

What it means

GetSchema(collectionName) only recognizes a fixed set of metadata collections: MetaDataCollections, ReservedWords, Tables, and Columns (DataSourceInformation and DataTypes are not implemented in this provider, unlike Microsoft.Data.Sqlite). Any other collectionName throws ArgumentException. The MetaDataCollections table returned by GetSchema() lists exactly what is supported, including the number of restrictions per collection (Tables and Columns: 4; the rest: 0).

Source

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

        if (string.Equals(collectionName, DbMetaDataCollectionNames.ReservedWords, StringComparison.OrdinalIgnoreCase))
        {
            ValidateRestrictions(collectionName, restrictionValues, 0);
            var table = new DataTable(DbMetaDataCollectionNames.ReservedWords);
            table.Columns.Add(DbMetaDataColumnNames.ReservedWord, typeof(string));
            foreach (var word in new[] { "ABORT", "ALTER", "CREATE", "DELETE", "DROP", "INSERT", "SELECT", "UPDATE" })
                table.Rows.Add(word);

            return table;
        }

        if (string.Equals(collectionName, "Tables", StringComparison.OrdinalIgnoreCase))
            return GetTablesSchema(collectionName, restrictionValues);

        if (string.Equals(collectionName, "Columns", StringComparison.OrdinalIgnoreCase))
            return GetColumnsSchema(collectionName, restrictionValues);

        throw new ArgumentException(Properties.Resources.UnknownCollection(collectionName));
    }

    public static void ClearAllPools()
    {
    }

    public static void ClearPool(SqliteConnection connection)
    {
        ArgumentNullException.ThrowIfNull(connection);
    }

    public new virtual SqliteTransaction BeginTransaction()
        => BeginTransaction(IsolationLevel.Unspecified);

    public virtual SqliteTransaction BeginTransaction(bool deferred)
        => BeginTransaction(IsolationLevel.Unspecified, deferred);

    public new virtual SqliteTransaction BeginTransaction(IsolationLevel isolationLevel)

View on GitHub (pinned to 6c72522679)

Solutions

  1. Call GetSchema() (no arguments) first and read the returned collection names; request only collections in that list.
  2. For metadata not exposed (indexes, FKs, views, triggers), query SQLite's catalog directly: 'SELECT * FROM sqlite_master' and PRAGMA statements (index_list, foreign_key_list).
  3. Wrap GetSchema in a helper that catches ArgumentException and falls back to sqlite_master queries.

Example fix

// before
var tbl = conn.GetSchema("ForeignKeys"); // throws: Unknown collection: ForeignKeys

// after
var tbl = conn.GetSchema("Tables"); // supported: MetaDataCollections, ReservedWords, Tables, Columns
// for anything else, use the catalog:
using var cmd = conn.CreateCommand();
cmd.CommandText = "SELECT name, sql FROM sqlite_master WHERE type = 'table'";
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<string> SupportedCollections = new(StringComparer.OrdinalIgnoreCase)
{ "MetaDataCollections", "ReservedWords", "Tables", "Columns" };

static DataTable SafeGetSchema(SqliteConnection conn, string collection, string?[]? restrictions = null)
{
    if (!SupportedCollections.Contains(collection))
        throw new ArgumentOutOfRangeException(nameof(collection), $"{collection} not supported; query sqlite_master instead.");
    return conn.GetSchema(collection, restrictions);
}

Type guard

static bool IsSupportedSchemaCollection(string name) =>
    name.Equals("MetaDataCollections", StringComparison.OrdinalIgnoreCase)
    || name.Equals("ReservedWords", StringComparison.OrdinalIgnoreCase)
    || name.Equals("Tables", StringComparison.OrdinalIgnoreCase)
    || name.Equals("Columns", StringComparison.OrdinalIgnoreCase);

Try / catch

null

Prevention

When it happens

Trigger: conn.GetSchema("Indexes"), GetSchema("ForeignKeys"), GetSchema("Views"), or GetSchema("DataSourceInformation"); generic schema-exploration tools (e.g. DataSet designers, SSDL generators, DB tooling) enumerating standard DbMetaDataCollectionNames; code ported from Microsoft.Data.Sqlite or System.Data.SqlClient expecting the full collection set.

Common situations: ORM/tooling compatibility layers that request standard collections, visual designers inspecting databases, and shared helpers written against richer providers.

Related errors


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