{"record":{"id":"c9021d418b58d515","repo":"HangfireIO/Hangfire","slug":"nameorconnectionstring","errorCode":null,"errorMessage":"nameOrConnectionString","messagePattern":"nameOrConnectionString","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.SqlServer/SqlServerStorage.cs","lineNumber":90,"sourceCode":"            : this(nameOrConnectionString, new SqlServerStorageOptions())\n        {\n        }\n\n        /// <summary>\n        /// Initializes SqlServerStorage from the provided SqlServerStorageOptions and either the provided connection\n        /// string or the connection string with provided name pulled from the application config file.       \n        /// </summary>\n        /// <param name=\"nameOrConnectionString\">Either a SQL Server connection string or the name of \n        /// a SQL Server connection string located in the connectionStrings node in the application config</param>\n        /// <param name=\"options\"></param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"nameOrConnectionString\"/> argument is null.</exception>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"options\"/> argument is null.</exception>\n        /// <exception cref=\"ArgumentException\"><paramref name=\"nameOrConnectionString\"/> argument is neither \n        /// a valid SQL Server connection string nor the name of a connection string in the application\n        /// config file.</exception>\n        public SqlServerStorage(string nameOrConnectionString, SqlServerStorageOptions options)\n        {\n            if (nameOrConnectionString == null) throw new ArgumentNullException(nameof(nameOrConnectionString));\n            if (options == null) throw new ArgumentNullException(nameof(options));\n\n            _connectionString = GetConnectionString(nameOrConnectionString);\n            _connectionFactory = DefaultConnectionFactory;\n            _options = options;\n\n            Initialize();\n        }\n\n        /// <summary>\n        /// Initializes a new instance of the <see cref=\"SqlServerStorage\"/> class with\n        /// explicit instance of the <see cref=\"DbConnection\"/> class that will be used\n        /// to query the data.\n        /// </summary>\n        public SqlServerStorage([NotNull] DbConnection existingConnection)\n            : this(existingConnection, new SqlServerStorageOptions())\n        {\n        }","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.SqlServer/SqlServerStorage.cs#L72-L108","documentation":"The SqlServerStorage constructor received a null nameOrConnectionString argument. This is a standard ArgumentNullException guard at the top of the (string, SqlServerStorageOptions) constructor, thrown before any connection-string resolution occurs.","triggerScenarios":"Passing a null string to new SqlServerStorage(...) or config.UseSqlServerStorage(null, options); a variable that was never assigned before being passed.","commonSituations":"Reading a connection string name from configuration that is missing (returns null); passing an uninitialized string variable; refactoring that removes the assignment.","solutions":["Ensure the nameOrConnectionString variable is assigned a non-null value before constructing the storage.","If the value comes from configuration, provide a fallback or validate it is not null before use.","Use the IGlobalConfiguration extension methods which also guard against this."],"exampleFix":"// before\nvar connName = config[\"HangfireConn\"]; // null if missing\nvar storage = new SqlServerStorage(connName, options);\n// after\nvar connName = config[\"HangfireConn\"] ?? throw new InvalidOperationException(\"HangfireConn not configured\");\nvar storage = new SqlServerStorage(connName, options);","handlingStrategy":"validation","validationCode":"string nameOrConnectionString = /* from config or variable */;\nif (nameOrConnectionString == null)\n    throw new InvalidOperationException(\"nameOrConnectionString must be set before creating SqlServerStorage.\");\n\nvar storage = new SqlServerStorage(nameOrConnectionString, options);","typeGuard":"static bool IsValidConnectionStringArg(string value) => !string.IsNullOrWhiteSpace(value);","tryCatchPattern":null,"preventionTips":["Always initialize connection string variables before passing them to SqlServerStorage.","Provide a fallback or fail-fast if the config value is missing.","Use nameof(nameOrConnectionString) in your own guard for clarity."],"tags":["argument-null","constructor","connection-string","validation"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}