I believe it means it cannot connect to your database. Are those the correct login details for your db? I use localdb(sqlexpress) so I just need the basic windows authentication. Connect to the table that you want to connect to using visual studio and get the correct connection string there. That’s my thinking on the error.
We could not determine what the cause was. To get around it, we manually created an empty Hangfire database before re-attempting the above steps. Once we did that, and ran the steps, the tables and such were created in the Hangfire database.
Facing same issue with you. And I have just gone with a workaround solution.
Create an empty Context:
public class HangfireContext : DbContext
public HangfireContext(DbContextOptions options) : base(options)
Run migrate before use HangfireServer
// Migrate and seed the database during startup. Must be synchronous.
using (var serviceScope = app.ApplicationServices.GetRequiredService()
Have a look at SqlServerStorageOptions. You should be able to set an option called PrepareSchemaIfNecessary and set it to true. We set ours to false as our process is to create all DBs before deploying code.
I tried the below, but it made no difference. Still get the same error:
"An exception of type ‘System.Data.SqlClient.SqlException’ occurred in System.Data.SqlClient.dll but was not handled in user code
Cannot open database “Hangfire” requested by the login. The login failed.
var hangfireOptions = new SqlServerStorageOptions
PrepareSchemaIfNecessary = true
config.UseSqlServerStorage(@"Server=localhost; Database=Hangfire; Trusted_Connection=True;", hangfireOptions);