No database provider has been configured 🟪 .NET

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.

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:

🧠 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.