How to configure HangFire SQL connection timeout?

I have a recurring job that is throwing the exception below. I thought it was something wrong with the stored procedure, but it’s okay. I replaced it with “WAITFOR DELAY ‘00:00:30’;” instead of the sql script in the stored procedure and still get the same error. The store procedure runs in SSMS no problem. I thought the following would set the command timeout for hangfire’s sql connection, but it does not work.

        // set hangfire sql server connection timeout minutes
        SqlServerStorageOptions options = new SqlServerStorageOptions()
        {
            CommandTimeout = TimeSpan.FromMinutes(10),
        };

        // configure hangfire sql server storage
        GlobalConfiguration.Configuration.UseSqlServerStorage("HangFire_ConnectionString", options);

How to resolve this issue. Thanks, Gary.

Thrown Exception
System.Data.EntityCommandExecutionException: An error occurred while executing the command definition. See the inner exception for details. —> System.Data.SqlClient.SqlException: Execution Timeout Expired. The timeout period elapsed prior to completion of the operation or the server is not responding. —> System.ComponentModel.Win32Exception: The wait operation timed out
— End of inner exception stack trace —
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() at System.Data.SqlClient.SqlDataReader.get_MetaData() at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption, Boolean shouldCacheForAlwaysEncrypted) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry)
at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method)
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
— End of inner exception stack trace —
at System.Data.EntityClient.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
at System.Data.Objects.ObjectContext.CreateFunctionObjectResult[TElement](EntityCommand entityCommand, ReadOnlyMetadataCollection`1 entitySets, EdmType edmTypes, MergeOption mergeOption)
at System.Data.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, MergeOption mergeOption, ObjectParameter parameters)
at System.Data.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ObjectParameter parameters)
at IBMS.Inventory.InventoryContainer.Refresh_Inventory_MonthlyClosingQOnHand() in D:\github\IMS\IMS\IBMS.Inventory\Inventory.cs:line 3776
at IBMS.Inventory.InventoryService.RefreshInventoryMonthlyClosingQOnHand() in D:\github\IMS\IMS\IBMS.Inventory\InventoryService.cs:line 139
at BLL.InventoryBLL.RefreshInventoryMonthlyClosingQOnHandJob() in D:\github\IMS\IMS\IBMS.BLL\BLL\InventoryBLL.cs:line 14708
at IBMS.Jobs.Job.RefreshInventoryMonthlyClosingQOnHandJob.Execute() in D:\github\IMS\IMS\IBMS.Jobs\Job\RefreshInventoryMonthlyClosingQOnHandJob.cs:line 30

Resolved issue. I needed to set the CommandTimeout for Entity Framework. Considering the size and complexity of the application, I’m really surprised I have not seen this issue years ago.