{"record":{"id":"3c8c43056c35e670","repo":"dotnet/efcore","slug":"no-relational-database-providers-are-configured-c","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs","lineNumber":422,"sourceCode":"        return clone;\n    }\n\n    /// <summary>\n    ///     Finds an existing <see cref=\"RelationalOptionsExtension\" /> registered on the given options\n    ///     or throws if none has been registered. This is typically used to find some relational\n    ///     configuration when it is known that a relational provider is being used.\n    /// </summary>\n    /// <param name=\"options\">The context options to look in.</param>\n    /// <returns>The extension.</returns>\n    public static RelationalOptionsExtension Extract(IDbContextOptions options)\n    {\n        var relationalOptionsExtensions\n            = options.Extensions\n                .OfType<RelationalOptionsExtension>()\n                .ToList();\n\n        return relationalOptionsExtensions.Count == 0\n            ? throw new InvalidOperationException(RelationalStrings.NoProviderConfigured)\n            : relationalOptionsExtensions.Count > 1\n                ? throw new InvalidOperationException(RelationalStrings.MultipleProvidersConfigured)\n                : relationalOptionsExtensions[0];\n    }\n\n    /// <summary>\n    ///     Adds the services required to make the selected options work. This is used when there\n    ///     is no external <see cref=\"IServiceProvider\" /> and EF is maintaining its own service\n    ///     provider internally. This allows database providers (and other extensions) to register their\n    ///     required services when EF is creating a service provider.\n    /// </summary>\n    /// <param name=\"services\">The collection to add services to.</param>\n    public abstract void ApplyServices(IServiceCollection services);\n\n    /// <summary>\n    ///     Gives the extension a chance to validate that all options in the extension are valid.\n    ///     Most extensions do not have invalid combinations and so this will be a no-op.\n    ///     If options are invalid, then an exception should be thrown.","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalOptionsExtension.cs#L404-L440","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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."],"exampleFix":"// before: no provider configured\npublic class MyContext : DbContext { }\n\n// after\npublic class MyContext : DbContext\n{\n    protected override void OnConfiguring(DbContextOptionsBuilder o)\n        => o.UseSqlServer(Configuration.GetConnectionString(\"Default\"));\n}","handlingStrategy":"validation","validationCode":"// Assert at startup that a relational provider is registered.\nusing var context = scope.ServiceProvider.GetRequiredService<MyContext>();\nvar ext = context.Database.GetService<IDbContextOptions>().Extensions\n    .OfType<Microsoft.EntityFrameworkCore.Infrastructure.RelationalOptionsExtension>().ToList();\nif (ext.Count == 0) throw new InvalidOperationException(\"No relational provider registered.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["provider","configuration","startup"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}