{"record":{"id":"70ddd96740b76254","repo":"HangfireIO/Hangfire","slug":"connection-70ddd9","errorCode":null,"errorMessage":"connection","messagePattern":"connection","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/Hangfire.SqlServer/SqlServerObjectsInstaller.cs","lineNumber":44,"sourceCode":"    {\n        [Obsolete(\"This field is unused and will be removed in 2.0.0.\")]\n        public static readonly int RequiredSchemaVersion = 5;\n\n        public static readonly int LatestSchemaVersion = 9;\n\n        public static void Install(DbConnection connection)\n        {\n            Install(connection, null);\n        }\n\n        public static void Install(DbConnection connection, string schema)\n        {\n            Install(connection, schema, false);\n        }\n\n        public static void Install(DbConnection connection, string schema, bool enableHeavyMigrations)\n        {\n            if (connection == null) throw new ArgumentNullException(nameof(connection));\n\n            var script = GetInstallScript(schema, enableHeavyMigrations);\n\n            connection.Execute(script, commandTimeout: 0);\n        }\n\n        public static string GetInstallScript(string schema, bool enableHeavyMigrations)\n        {\n            var script = GetStringResource(\n                typeof(SqlServerObjectsInstaller).GetTypeInfo().Assembly,\n                \"Hangfire.SqlServer.Install.sql\");\n\n            script = script.Replace(\"$(HangFireSchema)\", !string.IsNullOrWhiteSpace(schema) ? schema : Constants.DefaultSchema);\n\n            if (!enableHeavyMigrations)\n            {\n                script = script.Replace(\"--SET @DISABLE_HEAVY_MIGRATIONS = 1;\", \"SET @DISABLE_HEAVY_MIGRATIONS = 1;\");\n            }","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/HangfireIO/Hangfire/blob/c236dd0f930f831ec151e436e138ddc429a02a72/src/Hangfire.SqlServer/SqlServerObjectsInstaller.cs#L26-L62","documentation":"The SqlServerObjectsInstaller.Install method received a null connection argument. This is a standard ArgumentNullException guard at the top of the Install(DbConnection, string, bool) overload that executes the schema installation SQL script.","triggerScenarios":"Calling SqlServerObjectsInstaller.Install(null, schema); a connection that failed to open or was never created being passed to schema installation.","commonSituations":"Custom initialization code that creates a connection conditionally and passes null on the failure path; DI misconfiguration; testing helpers that skip connection creation.","solutions":["Ensure a valid, open DbConnection is passed to Install.","Create and open the connection before calling Install, disposing it afterward.","Add a null check with a meaningful message before calling Install."],"exampleFix":"// before\nSqlServerObjectsInstaller.Install(maybeNullConnection, \"Hangfire\");\n// after\nusing var conn = new SqlConnection(connectionString);\nconn.Open();\nSqlServerObjectsInstaller.Install(conn, \"Hangfire\");","handlingStrategy":"validation","validationCode":"DbConnection connection = /* creation */;\nif (connection == null)\n    throw new InvalidOperationException(\"Cannot install schema: connection is null.\");\nif (connection.State != ConnectionState.Open)\n    connection.Open();\n\nSqlServerObjectsInstaller.Install(connection, schema);","typeGuard":"static bool IsInstallableConnection(DbConnection conn) => conn != null && conn.State == ConnectionState.Open;","tryCatchPattern":null,"preventionTips":["Create and open the DbConnection before calling Install.","Wrap the connection in a using-statement to ensure disposal.","Use a null check with a clear error if the connection source may be null."],"tags":["argument-null","schema-install","dbconnection","validation"],"backgroundTag":null,"analyzedSha":"c236dd0f930f831ec151e436e138ddc429a02a72","analyzedAt":"2026-08-13T20:27:11.027Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}