InvalidOperationException: The ConnectionString property has not been initialized
The database connection was opened with an empty connection string — the configuration key wasn’t found.
The ConnectionString property has not been initializedConnectionString property has not been initializedValue cannot be null. (Parameter 'connectionString') Meaning
GetConnectionString("Default") returns null when the name doesn’t match appsettings.json, the file isn’t copied to output, the environment-specific file is missing, or the environment variable uses the wrong format (ConnectionStrings__Default).
Common causes
- Name mismatch between code and ConnectionStrings section
- appsettings.json not copied to output / wrong ASPNETCORE_ENVIRONMENT
- Env var not using double underscores
- Secret stored only in user-secrets on another machine
⚡ Quick fix
- Log builder.Configuration.GetConnectionString("Default") at startup
- Match the name exactly
- Set ConnectionStrings__Default in the environment for production
Detailed fix by platform
C#
- csharp
var cs = builder.Configuration.GetConnectionString("Default") ?? throw new InvalidOperationException("ConnectionStrings:Default missing"); builder.Services.AddDbContext<AppDb>(o => o.UseSqlServer(cs));
How to diagnose
- Config — Value at startup
- Environment — ASPNETCORE_ENVIRONMENT
- File — Copied to bin?
🔧 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