Search code examples
.netsql-serverweb-configconnection-stringhangfire

.NET Hangfire, DB connections specific to jobs


Using Hangfire I have jobs (inherited code I need to integrate as is) that require a different user (different permissions) to connect to the DB.

Configured are two connection strings in my web.config.

During startup I use UseSqlServerStorage to set it to one of the connection strings and that's fine.

Now I cannot figure out how to switch over to the other for a certain job.

I tried to set UseSqlServerStorage to the other connection string as part of the job (and set it back after the job is complete) but I doesn't switch to the other connection string at all.

I bingoogled it but it doesn't seem to be common practice. Am I overlooking something, should this be done differently altogether?

I basically just want to use a different DB user for different jobs so the existing DB users and their permissions can be used.


Solution

  • The connection string used for Hangfire has nothing to do with the connection string used by your application logic. Just have your application logic read its connection string from a separate location.