# InvalidOperationException: No database provider has been configured for this DbContext

**Code:** `No database provider has been configured` · **Category:** .NET · **Seen on:** .NET

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

## 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

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/dotnet/no-database-provider-configured)
