We left Russia. We are against aggression and war with Ukraine. It is a tragedy for our nations, it is a nightmare

Transaction management without TransactionScope

Hi, I am trying to use hangfire with an old project. There is not an option for me to use TransactionScope because multiple SqlConnections can be opened at the same time and that needs MSDTC support which i can not supply.

So, while searching the forum, i saw a usage like this;

var storage = new SqlServerStorage(mySqlConnection);
var client = new BackgroundJobClient(storage);

But when i use mySqlConnection with a transaction which is already started, i get an eror when i call client.Enqueue method ;

“ExecuteReader requires the command to have a transaction when the connection assigned to the command is in a pending local transaction. The Transaction property of the command has not been initialized”

This make me think that, the SqlCommand which is used in hangfire, needs the transaction of mySqlConnection object started.

This is the code i try;

SqlConnection mySqlConnection = new SqlConnection(connectionString);
mySqlConnection .BeginTransaction();
var storage = new SqlServerStorage(mySqlConnection);
var client = new BackgroundJobClient(storage);
client.Enqueue(() => Run(queueEntity.RecId));

Is there any other way for me to handle transactions?

I’m having the exact same problem.
Any updates on this?

Here’s the link to the original github issue that resulted in this feature being added: https://github.com/HangfireIO/Hangfire-Documentation/issues/5

Did anybody make any progress on this issue? Will start going through the code to see what’s going on in the mean time, but any assistance would be greatly appreciated.

Having done a bit more investigation - it appears this would be resolved using transaction scope as then the transaction would be ambient. Currently using service stack so an alternate I guess would be to create a storage provider based on this?

Would you be able to give any steer on this issue @odinserj?