Entity Framework Context Connection String changes at runtime

I have successfully installed Hangfire to my web application, and I can schedule jobs as expected. But when a job executes, the method it calls makes use of a Context class to access the database. The connection string inside the context object is different from the one I used in the Startup class to initialize Hangfire. I end up with the error:

“A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 50 - Local Database Runtime error occurred. Cannot create an automatic instance. See the Windows Application event log for error details.)”

The connection string it tries to use is: “Data Source=(localdb)\v11.0;AttachDbFilename=|DataDirectory|Intranet.Data.IntranetContext.mdf;Initial Catalog=Intranet.Data.IntranetContext;Integrated Security=True;MultipleActiveResultSets=True”

But the one I set to use in Startup is: “.UseSqlServerStorage(@“Server=.;database=Intranet;IntegratedSecurity=True;MultipleActiveResultSets=True;””

Any help would be greatly appreciated!

did you try using the overload in yours registration?

public static IGlobalConfiguration UseSqlServerStorage([NotNull] this IGlobalConfiguration configuration, [NotNull] Func connectionFactory, [NotNull] SqlServerStorageOptions options);