dotnet/efcore · critical · InvalidOperationException
No relational database providers are configured. Configure a
Error message
No relational database providers are configured. Configure a database provider using 'OnConfiguring' or by creating an ImmutableDbContextOptions with a configured database provider and passing it to the context.
What it means
Thrown by RelationalOptionsExtension.Extract(IDbContextOptions) at line 422 when no RelationalOptionsExtension is found among the context's options extensions. This means no relational database provider (SqlServer, Npgsql, SQLite, etc.) has been registered via UseSqlServer/UseNpgsql/UseSqlite etc. The Extract method is used internally whenever relational-specific configuration is accessed.
Source
Thrown at src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs:422
return clone;
}
/// <summary>
/// Finds an existing <see cref="RelationalOptionsExtension" /> registered on the given options
/// or throws if none has been registered. This is typically used to find some relational
/// configuration when it is known that a relational provider is being used.
/// </summary>
/// <param name="options">The context options to look in.</param>
/// <returns>The extension.</returns>
public static RelationalOptionsExtension Extract(IDbContextOptions options)
{
var relationalOptionsExtensions
= options.Extensions
.OfType<RelationalOptionsExtension>()
.ToList();
return relationalOptionsExtensions.Count == 0
? throw new InvalidOperationException(RelationalStrings.NoProviderConfigured)
: relationalOptionsExtensions.Count > 1
? throw new InvalidOperationException(RelationalStrings.MultipleProvidersConfigured)
: relationalOptionsExtensions[0];
}
/// <summary>
/// Adds the services required to make the selected options work. This is used when there
/// is no external <see cref="IServiceProvider" /> and EF is maintaining its own service
/// provider internally. This allows database providers (and other extensions) to register their
/// required services when EF is creating a service provider.
/// </summary>
/// <param name="services">The collection to add services to.</param>
public abstract void ApplyServices(IServiceCollection services);
/// <summary>
/// Gives the extension a chance to validate that all options in the extension are valid.
/// Most extensions do not have invalid combinations and so this will be a no-op.
/// If options are invalid, then an exception should be thrown.View on GitHub (pinned to dbf9771522)
Solutions
- Add a provider call in OnConfiguring: optionsBuilder.UseSqlServer(connectionString).
- If using DI: builder.Services.AddDbContext<MyContext>(o => o.UseSqlServer(connStr)).
- If this is a test, switch from UseInMemoryDatabase to UseSqlite/UseSqlServer or use the provider's in-memory/test double.
- Ensure conditional provider logic always registers exactly one provider.
Example fix
// before: no provider configured
public class MyContext : DbContext { }
// after
public class MyContext : DbContext
{
protected override void OnConfiguring(DbContextOptionsBuilder o)
=> o.UseSqlServer(Configuration.GetConnectionString("Default"));
} Defensive patterns
Strategy: validation
Validate before calling
// Assert at startup that a relational provider is registered.
using var context = scope.ServiceProvider.GetRequiredService<MyContext>();
var ext = context.Database.GetService<IDbContextOptions>().Extensions
.OfType<Microsoft.EntityFrameworkCore.Infrastructure.RelationalOptionsExtension>().ToList();
if (ext.Count == 0) throw new InvalidOperationException("No relational provider registered."); Prevention
- Always call UseXxxProvider() in OnConfiguring or AddDbContext.
- Write a startup smoke test that creates the context and runs a trivial query.
- Guard conditional provider selection with a default/else branch that throws if no provider was selected.
When it happens
Trigger: Creating a DbContext without calling any Use<Provider>() in OnConfiguring or via AddDbContext options. Or calling relational-specific APIs (like getting a relational connection or migrations) on a context configured only with an in-memory provider (UseInMemoryDatabase).
Common situations: Forgetting to configure a provider in OnConfiguring or Program.cs. Using UseInMemoryDatabase for testing but then calling relational APIs. A DI registration that doesn't chain .UseSqlServer(). Conditional provider selection that falls through without registering any.
Related errors
- Multiple relational database provider configurations found.
- Cosmos-specific methods can only be used when the context is
- None of connection string, CredentialToken, account key or a
- Unable to find expected assembly attribute [DesignTimeProvid
- The provider '{provider}' is not a Relational provider and t
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/3c8c43056c35e670.
Report an issue: GitHub.