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.
No database provider has been configured for this DbContextA provider can be configured by overriding the 'DbContext.OnConfiguring' method 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
- Register: services.AddDbContext<AppDb>(o => o.UseSqlServer(cs))
- Add public AppDb(DbContextOptions<AppDb> options) : base(options) {}
- Resolve the context from DI
Detailed fix by platform
C#
- csharp
public class AppDb : DbContext { public AppDb(DbContextOptions<AppDb> options) : base(options) { } }
How to diagnose
- Registration — AddDbContext call
- Constructor — Accepts options?
- 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:
Similar errors
Most viewed in .NET
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- Unable to cast object of type System.InvalidCastException: Unable to cast object of type 'X' to type 'Y'
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 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.
Report a correction or suggest an improvement
Last updated 13 Oct 2026