Skip to content
Latchkey

ASP.NET Core connection string null / not found in CI

Configuration returned no value for the connection string, so GetConnectionString("Default") was null. In CI the string usually lives in appsettings only for local dev, or is expected from an environment variable that was never set.

What this error means

The app fails with "System.ArgumentException: The ConnectionString property has not been initialized." or EF "No connection string named 'Default' was found." even though it works locally.

.NET
System.InvalidOperationException: A named connection string was used, but the name
'Default' was not found in the application's configuration.

Common causes

The string is only in a local config source

The connection string lives in appsettings.Development.json or user-secrets that are not present in CI, and nothing supplies it there.

The environment variable name is wrong

The value is expected from an env var but the key does not match the ConnectionStrings:Default binding (must be ConnectionStrings__Default).

How to fix it

Provide the connection string via environment

  1. Set ConnectionStrings__Default in the CI step env from a secret.
  2. Confirm GetConnectionString("Default") maps to that key (double underscore = colon).
  3. Do not commit real connection strings; use CI secrets.
.github/workflows/ci.yml
env:
  ConnectionStrings__Default: Host=localhost;Database=app;Username=postgres;Password=postgres

Fail fast on a missing string

Read the value with a required check so a missing configuration produces a clear error at startup.

Program.cs
var cs = builder.Configuration.GetConnectionString("Default")
    ?? throw new InvalidOperationException("ConnectionStrings:Default not configured");

How to prevent it

  • Supply CI connection strings via ConnectionStrings__ environment variables from secrets.
  • Keep local-only strings out of the config CI relies on.
  • Validate required configuration at startup so gaps fail fast.

Frequently asked questions

What causes "GetConnectionString returns null"?
The connection string lives in appsettings.Development.json or user-secrets that are not present in CI, and nothing supplies it there.
How do I fix GetConnectionString returns null?
Provide the connection string via environment

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card