We left Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Hangfire configuration for SQL Server

I am coding a MVC 5 internet application, and am wishing to use Hangfire for recurring tasks.

How can I setup Hangfire to use SQL Server storage without specifying this in the Startup.Auth ConfigureAuth(IAppBuilder app) function.

Here is a resource link for SQL Server configuration: http://docs.hangfire.io/en/latest/configuration/using-sql-server.html

This resource states that:

If you want to use Hangfire outside of web application, where OWIN
Startup class is not applicable, create an instance of the
SqlServerStorage manually and pass it to the JobStorage.Current static
property. Parameters are the same.

The example code is as follows:

JobStorage.Current = new SqlServerStorage("connection string or its name");

I have tried the following code (with my own connection string), yet the dashboard is not available. I have called the code above from a controller function.

Is there something that I have not done correct? How can I setup Hangfire to use SQL Server storage without using the Startup.Auth class?

Thanks in advance.

The Dashboard is not related to the storage. As far as I can see, the Dashboard is available only through the Startup class. Is there a reason you don’t want to use it?

1 Like

You will probably need something like in this example below and manually start the background server job.
Be wary of the graceful shutdown of job though.

http://docs.hangfire.io/en/latest/deployment-to-production/making-aspnet-app-always-running.html