Use Hangfire with SQLite in ASP.Net 4.5.

I’ll install Hangfire with SQLite, which could be quick and easy solution for small projects, which do not need full blown DB server.

Versions of each framework and libraries are as follow.

APS.Net MVC 4.5.2
Hangfire SQLite extension

Confusion selecting correct SQLite library.

When go to page, we can see the extension list as below.


I will use Hangfire SQLite version 1.1.1, but if you click project name, Hangfire SQLite, it goes to which is not the source code of Hangfire SQLite nuget 1.1.1. This source code in github is not working version.

Actually, is the source code of nuget 1.1.1 and this is the working version. So, if you want to look into the source code, be careful about this.


Just for a purpose of demonstration, install ASP.Net MVC 4.5.2 using default project template in VS2015 and install SQLite using Nuget.


This should install System.Data.SQLite, System.Data.SQLite.EF and System.Data.SQLite.Linq


install Hangfire using Nuget.


This will install Hangfire.Core and Hangfire.SqlServer


install Hangfire SQLite extention using Nuget.


This will install Hangfire.SQLite


Do configuration and add a recurring job in Startup.cs


When configuring Hangfire to work with SQLite, use UseSQLiteStorage() and use connection string name, SQLiteHangfire, which can be anything and will declare it later in Web.config

As SQLite cannot handle concurrent request, set WorkerCount = 1.

Just for testing, I add a recurring job to print current time in VS output window in every one minute.

public void Configuration(IAppBuilder app)

 // Hangfire configuration
 var options = new SQLiteStorageOptions();
 GlobalConfiguration.Configuration.UseSQLiteStorage("SQLiteHangfire", options);
 var option = new BackgroundJobServerOptions { WorkerCount = 1};

 // Add scheduled jobs
 RecurringJob.AddOrUpdate(() => Run(), Cron.Minutely);

public void Run()
 Debug.WriteLine($"Run at {DateTime.Now}");

Add connection string as below so that SQLite can be accessed.

 <add name="SQLiteHangfire" connectionString="Data Source=E:\OneDrive\SourceCodes\Study\ASPNetHangfireSQLite\ASPNetHangfireSQLite\App_Data\Hangfire.sqlite" providerName="System.Data.SQLite.EF6" />

All done, now let’s run and browse to “/hangfire” by typing as such.


Cool, hangfire launched and looks working. One recurring job has been registered.


Jobs are running every minute.


Looking at the folder SQL database to be exist, SQLite database automatically created without any extra work, which is really nice feature.


In VS output window, we can see timestamp is written every minute, however the timestamp was not exactly every minute. I’m not sure why there is a few seconds diffrence between recurring run.



In summary, we could set up ASP.Net MVC with Hangfire and SQLite, which was straightforward. Hangfire was easy to set up. Dashboard was convenient to monitor and manage jobs. Automatically created database schema was pretty impressive.

Running this a few days, I could see a few issues.

  1. Hangfire server become 2 servers and 0 server, rather than keep 1 server.  It looks not confident about Hangfire with SQLite, but recurring job worked as expected during those times.
  2. SQLite database size keep increasing, which is concern in terms of performance once the size reached at some point. I think we may need some regular maintenance to keep the size and maintain performance.




  1. Thanks for sharing.

    The “timestamp was not exactly every minute” issue is due to 15s QueuePollInterval by default. You can set a minor value to increase precision:
    new SQLiteStorageOptions() { QueuePollInterval = TimeSpan.FromSeconds(1) });
    (The side effect is higher frequency of database query.)

    1. Thanks for the tip, darkthread.

      That’s good to know. I’ll definitely get a benefit from this option in case I need more precision.


Leave a comment

Your email address will not be published. Required fields are marked *