ConnectionString property has not been initialized .NET Origin: Application & API OSI layer 7 · Application Last updated 13 Oct 2026

InvalidOperationException: The ConnectionString property has not been initialized

The database connection was opened with an empty connection string — the configuration key wasn’t found.

Exact message you may see The ConnectionString property has not been initializedConnectionString property has not been initializedValue cannot be null. (Parameter 'connectionString')
Seen on: .NET

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

  1. Log builder.Configuration.GetConnectionString("Default") at startup
  2. Match the name exactly
  3. Set ConnectionStrings__Default in the environment for production

Detailed fix by platform

C#

  1. csharp
    var cs = builder.Configuration.GetConnectionString("Default")
        ?? throw new InvalidOperationException("ConnectionStrings:Default missing");
    builder.Services.AddDbContext<AppDb>(o => o.UseSqlServer(cs));

How to diagnose

  1. Config — Value at startup
  2. Environment — ASPNETCORE_ENVIRONMENT
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

1000 — Cloudflare Error 1000: DNS points to prohibited IP (Cloudflare)10001001 — Cloudflare Error 1001: DNS resolution error (Cloudflare)10011002 — Cloudflare Error 1002: DNS points to Prohibited IP / Restricted (Cloudflare)10021004 — Cloudflare Error 1004: Host Not Configured to Serve Web Traffic (Cloudflare)10041018 — Cloudflare Error 1018: Could not find host (Cloudflare)10181034 — Cloudflare Error 1034: Edge IP Restricted (Cloudflare)10341046 — MySQL ERROR 1046 (3D000): No database selected (MySQL)10461049 — MySQL ERROR 1049 (42000): Unknown database 'x' (MySQL)1049Connectio…

Explore the map of this error Full error map →

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