HangfireIO/Hangfire · error · ArgumentException
Could not find connection string with name '{nameOrConnectio
Error message
Could not find connection string with name '{nameOrConnectionString}' in application config file What it means
Hangfire could not resolve the provided nameOrConnectionString value into a usable connection string. The value contained no semicolon (so it was not a raw connection string) and was not found in the application's connectionStrings configuration section. This code path only runs under the FEATURE_CONFIGURATIONMANAGER build target (full .NET Framework).
Source
Thrown at src/Hangfire.SqlServer/SqlServerStorage.cs:541
{
var defaultQueueProvider = _options.DefaultQueueProvider ?? new SqlServerJobQueueProvider(this, _options);
QueueProviders = new PersistentJobQueueProviderCollection(defaultQueueProvider);
}
private static string GetConnectionString(string nameOrConnectionString)
{
#if FEATURE_CONFIGURATIONMANAGER
if (IsConnectionString(nameOrConnectionString))
{
return nameOrConnectionString;
}
if (IsConnectionStringInConfiguration(nameOrConnectionString))
{
return ConfigurationManager.ConnectionStrings[nameOrConnectionString].ConnectionString;
}
throw new ArgumentException(
$"Could not find connection string with name '{nameOrConnectionString}' in application config file");
#else
return nameOrConnectionString;
#endif
}
#if FEATURE_CONFIGURATIONMANAGER
private static bool IsConnectionString(string nameOrConnectionString)
{
return nameOrConnectionString.Contains(";");
}
private static bool IsConnectionStringInConfiguration(string connectionStringName)
{
var connectionStringSetting = ConfigurationManager.ConnectionStrings[connectionStringName];
return connectionStringSetting != null;
}View on GitHub (pinned to c236dd0f93)
Solutions
- Verify the exact name exists in the <connectionStrings> section of your app.config/web.config and matches what you pass to UseSqlServerStorage.
- Alternatively, pass the full connection string (containing a semicolon) directly instead of a name.
- Confirm the config file is present and copied to the output directory (Copy to Output Directory = Copy if newer).
Example fix
// before — name 'HangfireDB' not in config
config.UseSqlServerStorage("HangfireDB");
// after — add to app.config
// <connectionStrings>
// <add name="HangfireDB" connectionString="Server=.;Database=Hangfire;Integrated Security=true" providerName="System.Data.SqlClient" />
// </connectionStrings>
config.UseSqlServerStorage("HangfireDB");
// or pass the full connection string directly:
config.UseSqlServerStorage("Server=.;Database=Hangfire;Integrated Security=true"); Defensive patterns
Strategy: validation
Validate before calling
string nameOrConnectionString = /* from config */;
bool isRawConnectionString = nameOrConnectionString.Contains(";");
bool isInConfig = ConfigurationManager.ConnectionStrings[nameOrConnectionString] != null;
if (!isRawConnectionString && !isInConfig)
throw new InvalidOperationException($"Connection string '{nameOrConnectionString}' not found in config and is not a raw connection string."); Prevention
- Validate the connection string name exists in <connectionStrings> before passing it to UseSqlServerStorage.
- Prefer passing the full connection string (with semicolons) directly to avoid config-resolution ambiguity.
- Ensure app.config/web.config is deployed alongside the application binary.
When it happens
Trigger: Passing a connection-string name to the SqlServerStorage constructor or UseSqlServerStorage extension when that name is absent from <connectionStrings> in app.config/web.config; typo in the name; config file not deployed to the runtime directory.
Common situations: Mistyping the connection string name; app.config transformed incorrectly during publish; using a name from a different environment's config; deploying without the connectionStrings section; passing a partial connection string without a semicolon.
Related errors
- `DisableTransactionScope` option does not support external q
- Attempts value must be equal or greater than zero.
- DelaysInSeconds value must be an array of non-negative numbe
- client
- storage
AI-assisted analysis of HangfireIO/Hangfire@c236dd0f93 (2026-08-13).
Data as JSON: /api/errors/684b8046d01279bf.
Report an issue: GitHub.