1

I have a .net core application which has hangfire 1.7.2 running.

So I have this job, which executes SQL stored procedure and its a long running task, can be of 30 minutes.

This gives me following error: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding. The statement has been terminated.

services.AddHangfire(configuration => 

configuration.UseSqlServerStorage(Configuration.GetConnectionString("HangfireConnection"), 
new SqlServerStorageOptions
    {
        SlidingInvisibilityTimeout = TimeSpan.FromMinutes(30),
        QueuePollInterval = TimeSpan.Zero,
        UsePageLocksOnDequeue = false,
        DisableGlobalLocks = false
    }));

Please help me out.

jarlh
  • 42,561
  • 8
  • 45
  • 63
Gaurav
  • 122
  • 1
  • 2
  • 11

2 Answers2

4

The CommandTimeout property on SqlServerStorageOptions should be what you are looking for.

Increase this to be more than 30 minutes and your jobs will stop timing out.

(See source https://github.com/HangfireIO/Hangfire/blob/cf7bb08d24ee4953926b7717461bf8a23d895eb4/src/Hangfire.SqlServer/SqlServerConnection.cs)

Mattkwish
  • 753
  • 7
  • 16
  • 2
    I tried this answer but it was still the giving me same error, then I debugged it more and got to know that my SqlCommand was failing. It has its own CommandTimeout which is by default 30 secs. Your answer helped me debug more, thank you. – Gaurav Nov 15 '19 at 07:58
  • Glad i could be of some help! – Mattkwish Nov 15 '19 at 16:03
2

I managed to fix this by increasing SQLCommand timeout which is by default 30 seconds.

 using (SqlCommand cmd = new SqlCommand(query, con))
 {
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandTimeout = 3600; // 1 hour
        await cmd.ExecuteNonQueryAsync();
 }
Gaurav
  • 122
  • 1
  • 2
  • 11