{"record":{"id":"9eaa92eca854b424","repo":"dotnet/efcore","slug":"timeout-must-be-less-than-or-equal-to-int32-maxval","errorCode":null,"errorMessage":"Timeout must be less than or equal to Int32.MaxValue (2147483647) seconds. Provided timeout: {seconds} seconds.","messagePattern":"Timeout must be less than or equal to Int32\\.MaxValue \\(2147483647\\) seconds\\. Provided timeout: (.+?) seconds\\.","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs","lineNumber":972,"sourceCode":"    /// </remarks>\n    /// <param name=\"databaseFacade\">The <see cref=\"DatabaseFacade\" /> for the context.</param>\n    /// <param name=\"timeout\">The timeout to use.</param>\n    public static void SetCommandTimeout(this DatabaseFacade databaseFacade, TimeSpan timeout)\n    {\n        if (timeout == Timeout.InfiniteTimeSpan)\n        {\n            databaseFacade.SetCommandTimeout(0);\n            return;\n        }\n\n        if (timeout < TimeSpan.Zero)\n        {\n            throw new ArgumentException(RelationalStrings.TimeoutTooSmall(timeout.TotalSeconds));\n        }\n\n        if (timeout.TotalSeconds > int.MaxValue)\n        {\n            throw new ArgumentException(RelationalStrings.TimeoutTooBig(timeout.TotalSeconds));\n        }\n\n        databaseFacade.SetCommandTimeout(Convert.ToInt32(timeout.TotalSeconds));\n    }\n\n    /// <summary>\n    ///     Returns the timeout (in seconds) set for commands executed with this <see cref=\"DbContext\" />.\n    /// </summary>\n    /// <remarks>\n    ///     <para>\n    ///         Note that the command timeout is distinct from the connection timeout, which is commonly\n    ///         set on the database connection string.\n    ///     </para>\n    ///     <para>\n    ///         See <see href=\"https://aka.ms/efcore-docs-connections\">Connections and connection strings</see> for more information and examples.\n    ///     </para>\n    /// </remarks>\n    /// <param name=\"databaseFacade\">The <see cref=\"DatabaseFacade\" /> for the context.</param>","sourceCodeStart":954,"sourceCodeEnd":990,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Extensions/RelationalDatabaseFacadeExtensions.cs#L954-L990","documentation":"Thrown by RelationalDatabaseFacadeExtensions.SetCommandTimeout(TimeSpan) when timeout.TotalSeconds exceeds int.MaxValue (2147483647). ADO.NET command timeouts are expressed in whole seconds as int, so values beyond the int range cannot be applied.","triggerScenarios":"Calling Database.SetCommandTimeout(TimeSpan) with a value whose TotalSeconds > int.MaxValue — e.g. TimeSpan.MaxValue, or a multi-century duration from a config typo.","commonSituations":"Configuration supplying an enormous timeout (days/years) interpreted as seconds; passing Timeout.InfiniteTimeSpan intended as 'no limit' but instead passing a huge TimeSpan; unit tests using arbitrary large values.","solutions":["Cap the timeout at a sane maximum or use Timeout.InfiniteTimeSpan (which the API maps to 0) to mean no limit.","Validate and clamp TotalSeconds to <= int.MaxValue before calling.","Use the int-based SetCommandTimeout(int) overload with a bounded value."],"exampleFix":"// before\ncontext.Database.SetCommandTimeout(TimeSpan.FromDays(9999)); // throws TimeoutTooBig\n\n// after\nvar ts = TimeSpan.FromDays(1); // a bounded, sane value\ncontext.Database.SetCommandTimeout(ts);","handlingStrategy":"validation","validationCode":"TimeSpan ts = configuredTimeout;\nif (ts == Timeout.InfiniteTimeSpan)\n    context.Database.SetCommandTimeout(0);\nelse if (ts.TotalSeconds > int.MaxValue)\n    throw new ArgumentOutOfRangeException(nameof(configuredTimeout), $\"Timeout must be <= {int.MaxValue} seconds.\");\nelse if (ts < TimeSpan.Zero)\n    throw new ArgumentOutOfRangeException(nameof(configuredTimeout), \"Timeout must be >= 0.\");\nelse\n    context.Database.SetCommandTimeout(ts);","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Bound configured timeouts to a sensible maximum (e.g. hours, not days-in-seconds).","Use Timeout.InfiniteTimeSpan for no-limit rather than enormous values.","Prefer the int-seconds SetCommandTimeout overload with a clamped value."],"tags":["ef-core","relational","command-timeout","validation","overflow"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}