Hangfire: When use ReccuringJob that`s returning : Invalid object name 'HangFire.Hash'

Created on 13 Jul 2019  路  2Comments  路  Source: HangfireIO/Hangfire

When i`m use :
```
RecurringJob.AddOrUpdate(nameof(TaskDriver),
job => job.Run(JobCancellationToken.Null) ,
Cron.MinuteInterval(2),TimeZoneInfo.Local);

or another method from this class, 
i get error:


> Invalid object name 'HangFire.Hash'

In my startupclass i have:
In  configureService:

services.AddScoped();
services.AddHangfire((config) => {
var options = new SqlServerStorageOptions
{
PrepareSchemaIfNecessary = false,
QueuePollInterval = TimeSpan.FromHours(10)
};
config.UseSqlServerStorage("Server=(localdb)\mssqllocaldb;Database=CostsAnalyseDB;Trusted_Connection=True;MultipleActiveResultSets=true", options);
});

In Configure:  

app.UseHangfireServer(new BackgroundJobServerOptions { WorkerCount = 1 });
GlobalJobFilters.Filters.Add(new AutomaticRetryAttribute { Attempts = 0 });
app.UseHangfireDashboard();
ScheduleDriver.ScheduleReccuringJob();

ScheduleDriver contains :

RecurringJob.AddOrUpdate(nameof(TaskDriver),
job => job.Run(JobCancellationToken.Null) ,
Cron.MinuteInterval(2),TimeZoneInfo.Local);

In TaskDrive:

public class TaskDriver : ITask
{
private readonly ILogger _logger;
private readonly ApplicationContext _context;

    public TaskDriver(  ApplicationContext context)
    { 
        _context = context;
    }
    public async Task RunAtTimeOf(DateTime now)
    {
        //_logger.LogInformation("Task from schedule start.");

        //_logger.LogInformation("Task have been finished.");
    }
    public async  Task Run(IJobCancellationToken token)
    {
        token.ThrowIfCancellationRequested();
        await RunAtTimeOf(DateTime.Now);
    }
}

```
Versions of library:

PackageReference Include="Hangfire" Version="1.7.4"
PackageReference Include="Hangfire.AspNetCore" Version="1.7.4"
PackageReference Include="Hangfire.PostgreSql" Version="1.6.0"

Most helpful comment

Have you tried it with PrepareSchemaIfNecessary =true?

All 2 comments

Have you tried it with PrepareSchemaIfNecessary =true?

Yeah, sorry i'm blind, it's working =/.

Was this page helpful?
0 / 5 - 0 ratings