No database provider has been configured .NET Origin: Application & API OSI layer 7 · Application Last updated 13 Oct 2026

InvalidOperationException: No database provider has been configured for this DbContext

EF Core created a DbContext without UseSqlServer/UseNpgsql/UseSqlite — typically because the context was newed up manually or registered without options.

Exact message you may see No database provider has been configured for this DbContextA provider can be configured by overriding the 'DbContext.OnConfiguring' method
Seen on: .NET

Meaning

Configure the provider in AddDbContext or OnConfiguring, and make sure the DbContext has a constructor accepting DbContextOptions<T> passed to base.

Common causes

  • DbContext created with new instead of DI
  • Missing constructor taking DbContextOptions<T>
  • AddDbContext without a provider
  • Design-time tools can’t find the configuration

⚡ Quick fix

  1. Register: services.AddDbContext<AppDb>(o => o.UseSqlServer(cs))
  2. Add public AppDb(DbContextOptions<AppDb> options) : base(options) {}
  3. Resolve the context from DI

Detailed fix by platform

C#

  1. csharp
    public class AppDb : DbContext
    {
        public AppDb(DbContextOptions<AppDb> options) : base(options) { }
    }

How to diagnose

  1. Registration — AddDbContext call
  2. Constructor — Accepts options?
  3. Creation — new vs DI

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

1000 — Cloudflare Error 1000: DNS points to prohibited IP (Cloudflare)10001001 — Cloudflare Error 1001: DNS resolution error (Cloudflare)10011002 — Cloudflare Error 1002: DNS points to Prohibited IP / Restricted (Cloudflare)10021004 — Cloudflare Error 1004: Host Not Configured to Serve Web Traffic (Cloudflare)10041018 — Cloudflare Error 1018: Could not find host (Cloudflare)10181034 — Cloudflare Error 1034: Edge IP Restricted (Cloudflare)10341046 — MySQL ERROR 1046 (3D000): No database selected (MySQL)10461049 — MySQL ERROR 1049 (42000): Unknown database 'x' (MySQL)1049No databa…

Explore the map of this error Full error map →

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.