Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

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

Open DjeeBay opened this issue 6 years ago • 7 comments

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.

DjeeBay avatar Jun 20 '19 22:06 DjeeBay

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.

DjeeBay avatar Jun 21 '19 19:06 DjeeBay

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

ashab015 avatar Sep 03 '19 15:09 ashab015

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

palmtreefrb avatar Sep 06 '19 22:09 palmtreefrb

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

Perustaja avatar Sep 16 '19 03:09 Perustaja

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

my problem solved ,tankyou

ghostSmoker avatar Mar 26 '20 21:03 ghostSmoker

Thanks!

peota avatar Oct 21 '24 17:10 peota

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.

thank you this actually worked 👍🥰

Prikalel avatar May 24 '25 14:05 Prikalel