Hangfire: ASP.Net Core + SQLite "Could not find connection string"

Created on 21 Jun 2019  路  5Comments  路  Source: HangfireIO/Hangfire

Hi everyone !

I'm trying to use Hangfire.SQLite in an ASP.Net Core app (2.1.1) but I have the following error :

Could not find connection string with name 'Filename=./mydb.db' in application config file

Which is weird because in Startup.ConfigureServices() I use the db with services.AddDbContext<DataContext>(options => options.UseSqlite(@"Filename=./mydb.db")); and it's working fine with the exact same connection string.

I'm configuring Hangfire like this :

var sqliteOptions = new SQLiteStorageOptions();
services.AddHangfire(configuration => configuration
    .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
    .UseSimpleAssemblyNameTypeSerializer()
    .UseRecommendedSerializerSettings()
    //.UseMemoryStorage(new MemoryStorageOptions { JobExpirationCheckInterval = TimeSpan.FromMinutes(10) })
    .UseSQLiteStorage("Filename=psm.db", sqliteOptions)
);
services.AddHangfireServer();

As you can see, I've tested with the MemoryStorage extension and it works well, I have the dashboard and Jobs are executed successfully.

For information I've also tried the absolute path with Data Source instead of Filename, I've tried adding HangfireConnection key in appsettings.json etc. but always got the same error.

Thx for the help.

question

Most helpful comment

I've finally found a solution.
The reason why it's not working is weird IMO : you need to have a ; in your connection string.

You can find the responsible line here : https://github.com/wanlitao/HangfireExtension/blob/master/src/Hangfire.SQLite/SQLiteStorage.cs#L308

So adding a ; at the end of the string solved my problem.

All 5 comments

I've finally found a solution.
The reason why it's not working is weird IMO : you need to have a ; in your connection string.

You can find the responsible line here : https://github.com/wanlitao/HangfireExtension/blob/master/src/Hangfire.SQLite/SQLiteStorage.cs#L308

So adding a ; at the end of the string solved my problem.

I can confirm this works in after adding ";" at the end of the connection string.

I dicked with this for hours. Who would have known ";" was the issue :(

Had this issue as well. I had to put it in the json file itself or it would throw another error

I can confirm this works in after adding ";" at the end of the connection string.

my problem solved ,tankyou

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jeffsugden picture jeffsugden  路  4Comments

cbmek picture cbmek  路  3Comments

plmwong picture plmwong  路  3Comments

odinserj picture odinserj  路  4Comments

nsnail picture nsnail  路  3Comments