OrchardCMS/OrchardCore · critical · ArgumentOutOfRangeException

Unsupported database provider

Error message

Unsupported database provider

What it means

DbConnectionValidator.GetFactoryAndSqlDialect maps a DatabaseProviderValue to a concrete ADO.NET connection factory plus YesSql SQL dialect via a switch expression. The default arm throws ArgumentOutOfRangeException("Unsupported database provider") when the provider value does not match any of the four supported providers (SqlConnection, MySql, Sqlite, Postgres). This runs during tenant validation (ValidateAsync) before the shell is built, so an unrecognized provider string aborts tenant setup.

Solutions

  1. Set the tenant's DatabaseProvider in shell settings to one of the exact values the switch handles: SqlConnection, MySql, Sqlite, or Postgres.
  2. Verify the value stored in App_Data/Sites/{tenant}/appsettings.json (or the tenant's DatabaseProvider shell setting) has no typos, extra whitespace, or different casing.
  3. If you programmatically set shell settings for tenant provisioning, use the DatabaseProviderValue constants instead of raw strings.

Example fix

// before
"DatabaseProvider": "sqlserver"
// after
"DatabaseProvider": "SqlConnection"
Defensive patterns

Strategy: validation

Validate before calling

var supported = new[] { "SqlConnection", "MySql", "Sqlite", "Postgres" };
if (!supported.Contains(shellSettings["DatabaseProvider"]))
    throw new InvalidOperationException($"Provider '{shellSettings["DatabaseProvider"]}' is not supported. Use one of: {string.Join(", ", supported)}");

Try / catch

catch (ArgumentOutOfRangeException ex) { logger.LogError(ex, "Tenant {Tenant} has an unsupported database provider", tenant); return ValidationFailed; }

Prevention

When it happens

Trigger: Calling ValidateAsync (GetFactoryAndSqlDialect) with a DatabaseProviderValue other than SqlConnection/MySql/Sqlite/Postgres — typically a raw string like "sqlserver", "mssql", or an empty/garbage value in tenant appsettings under DatabaseProvider.

Common situations: Hand-edited tenant configuration (appsites/*.json) with a misspelled provider name; a provider casing/label change across Orchard Core versions; copy-pasting config from another CMS that names providers differently.

Related errors


AI-assisted analysis of OrchardCMS/OrchardCore@4306c0717f (2026-09-13). Data as JSON: /api/errors/4fe87e755e832152. Report an issue: GitHub.

Appendix: source

Thrown at src/OrchardCore/OrchardCore.Data.YesSql/DbConnectionValidator.cs:202

        sqlBuilder.Take("1");

        if (isShellDescriptorDocument)
        {
            sqlBuilder.WhereAnd($"Type = '{s_shellDescriptorTypeColumnValue}'");
        }

        return sqlBuilder.ToSqlString();
    }

    private static (IConnectionFactory connectionFactory, ISqlDialect sqlDialect) GetFactoryAndSqlDialect(
        string databaseProvider,
        string connectionString) => databaseProvider switch
        {
            DatabaseProviderValue.SqlConnection => (new DbConnectionFactory<SqlConnection>(connectionString), new SqlServerDialect()),
            DatabaseProviderValue.MySql => (new DbConnectionFactory<MySqlConnection>(connectionString), new MySqlDialect()),
            DatabaseProviderValue.Sqlite => (new DbConnectionFactory<SqliteConnection>(connectionString), new SqliteDialect()),
            DatabaseProviderValue.Postgres => (new DbConnectionFactory<NpgsqlConnection>(connectionString), new PostgreSqlDialect()),
            _ => throw new ArgumentOutOfRangeException(nameof(databaseProvider), "Unsupported database provider"),
        };

    private static SqlBuilder GetSqlBuilder(ISqlDialect sqlDialect, string tablePrefix, string tableNameSeparator)
    {
        var prefix = string.Empty;
        if (!string.IsNullOrWhiteSpace(tablePrefix))
        {
            prefix = tablePrefix.Trim() + tableNameSeparator;
        }

        return new SqlBuilder(prefix, sqlDialect);
    }
}

View on GitHub (pinned to 4306c0717f)