{"record":{"id":"32e8b73be4b2295d","repo":"microsoft/aspire","slug":"connectionstring-is-missing-it-should-be-provided-in","errorCode":null,"errorMessage":"ConnectionString is missing. It should be provided in 'ConnectionStrings:{connectionName}' or under the 'ConnectionString' key in '{defaultConfigSectionName}' or '{typeSpecificSectionName}' configuration section.","messagePattern":"ConnectionString is missing\\. It should be provided in 'ConnectionStrings:(.+?)' or under the 'ConnectionString' key in '(.+?)' or '(.+?)' configuration section\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Components/Common/ConnectionStringValidation.cs","lineNumber":16,"sourceCode":"// Licensed to the .NET Foundation under one or more agreements.\n// The .NET Foundation licenses this file to you under the MIT license.\n\nnamespace Aspire;\n\ninternal static class ConnectionStringValidation\n{\n    public static void ValidateConnectionString(string? connectionString, string connectionName, string defaultConfigSectionName, string? typeSpecificSectionName = null, bool isEfDesignTime = false)\n    {\n        if (string.IsNullOrWhiteSpace(connectionString) && !isEfDesignTime)\n        {\n            var errorMessage = (!string.IsNullOrEmpty(typeSpecificSectionName))\n                ? $\"ConnectionString is missing. It should be provided in 'ConnectionStrings:{connectionName}' or under the 'ConnectionString' key in '{defaultConfigSectionName}' or '{typeSpecificSectionName}' configuration section.\"\n                : $\"ConnectionString is missing. It should be provided in 'ConnectionStrings:{connectionName}' or under the 'ConnectionString' key in '{defaultConfigSectionName}' configuration section.\";\n\n            throw new InvalidOperationException(errorMessage);\n        }\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":20,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Components/Common/ConnectionStringValidation.cs#L1-L20","documentation":"Shared validation used by Aspire client integrations: a connection string is required before a client can be created. When the value is null/whitespace (and this is not an EF design-time context where a connection string is legitimately absent), it throws listing every configuration location that could supply the value.","triggerScenarios":"Calling any AddXxx client extension whose connection string resolution (ConnectionStrings:{name} or {section}:ConnectionString) produced an empty value at registration/factory time while isEfDesignTime is false.","commonSituations":"Database-less EF tooling scenarios aside: running outside AppHost, missing appsettings in CI, renamed connection name, configuration root not loaded (e.g. wrong environment), empty string in user secrets.","solutions":["Add ConnectionStrings:{connectionName} to appsettings.json, user secrets, or environment variables (ConnectionStrings__{connectionName}).","Provide the ConnectionString key in the component's configuration section if that path is supported.","Run through the Aspire AppHost with .WithReference(...) so the value is injected.","Verify the connection name string passed to the extension matches configuration exactly."],"exampleFix":"// before\nbuilder.AddSqlServerDbContext<SalesDbContext>(\"salesDb\"); // no ConnectionStrings:salesDb\n\n// after (appsettings.json)\n// { \"ConnectionStrings\": { \"salesDb\": \"Server=localhost;Database=Sales;Trusted_Connection=True\" } }\nbuilder.AddSqlServerDbContext<SalesDbContext>(\"salesDb\");","handlingStrategy":"validation","validationCode":"var cs = configuration.GetConnectionString(connectionName);\nif (string.IsNullOrWhiteSpace(cs))\n    throw new InvalidOperationException($\"Missing connection string '{connectionName}'. Add ConnectionStrings:{connectionName} to configuration.\");","typeGuard":null,"tryCatchPattern":"try { builder.AddSqlServerDbContext<MyDbContext>(name); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"ConnectionString is missing\"))\n{ /* emit which config sources were checked; abort startup */ }","preventionTips":["Keep a single list of required connection names and validate all of them at startup.","Use ConnectionStrings__{name} environment variables in containers/CI.","Run services through the Aspire AppHost so connection strings are injected automatically."],"tags":["connection-string","missing-configuration","shared-validation","multiple-integrations"],"backgroundTag":"missing-required-config","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T09:17:21.228Z"}