ConnectionString property has not been initialized 🟪 .NET

InvalidOperationException: The ConnectionString property has not been initialized

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

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:

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