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
- 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
- NullReferenceException System.NullReferenceException: Object reference not set to an instance of an object
- FileNotFoundException assembly Could not load file or assembly 'X, Version=…' or one of its dependencies
- InvalidOperationException InvalidOperationException: Unable to resolve service for type 'X' while attempting to activate 'Y'
Other ways to find it
🧠 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 7 Oct 2026