I know that this is old - but 9 months have passed already, and I also pulled out my hair - and decided to write about it here .
My solution was to simply create a quick and dirty DbContext, tell it the correct connection string and call Database.CreateIfNotExists in the constructor:
public class HangfireContext : DbContext { public HangfireContext() : base("name=HangfireContext") { Database.SetInitializer<HangfireContext>(null); Database.CreateIfNotExists(); } }
In the HangfireBootstrapper.Start () method, I am doing something like this:
public void Start() { lock (_lockObject) { if (_started) return; _started = true; HostingEnvironment.RegisterObject(this); //This will create the DB if it doesn't exist var db = new HangfireContext(); GlobalConfiguration.Configuration.UseSqlServerStorage("HangfireContext"); // See the next section on why we set the ServerName var options = new BackgroundJobServerOptions() { ServerName = ConfigurationManager.AppSettings["HangfireServerName"] }; _backgroundJobServer = new BackgroundJobServer(options); var jobStarter = DependencyResolver.Current.GetService<JobBootstrapper>(); //See the Recurring Jobs + SimpleInjector section jobStarter.Bootstrap(); } }
You donβt know why Hangfire has such difficulties with LocalDb - maybe it can only process full SQL instances? In any case, this works for me, the new team members and the new dev / staging / prod instances that got up.
Jack
source share