Hangfire icon indicating copy to clipboard operation
Hangfire copied to clipboard

Transaction management without TransactionScope

Open aliashab opened this issue 8 years ago • 7 comments

Transaction management without TransactionScope

https://discuss.hangfire.io/t/transaction-management-without-transactionscope/1128

use

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

aliashab avatar Sep 20 '17 10:09 aliashab

Any idea when this pull request might be completed and merged into a new version? This feature would help me out a lot.

wapplegate avatar Oct 07 '17 11:10 wapplegate

Is there any chance this pull request could be merged and a new version of Hangfire sent to Nuget containing these changes?

wapplegate avatar Oct 22 '17 18:10 wapplegate

@aliashab, thanks for your contribution! I think it's better to modify the UseConnection method to provide both DbConnection and DbTransaction parameters for its action, because otherwise things are messed a bit: connection is taken from a parameter, transaction is from a global scope.

_storage.UseConnection((connection, transaction) =>
{
    connection.Execute(/* ... */);
});

In this case the UseTransaction method will always create a new transaction, and the UseConnection method will allow to use an existing one.

odinserj avatar Nov 08 '17 10:11 odinserj

@Singularity222, there will be no quick fix for this, the change is planned to the next version only. To speed up the things, you could build your own version from sources, I understand that this is more complex usage.

odinserj avatar Nov 08 '17 10:11 odinserj

Any news on that one?

Ppiwow avatar Mar 13 '20 15:03 Ppiwow

Oh, yeah, would exactly need this for integrating Hangfire into a legacy application which uses DbTransactions instead of TransactionScope. Please consider this for 1.8.

ulrichb avatar Jun 29 '21 08:06 ulrichb

@odinserj As this PR is outdated and has some conflicts: If you lik,e I could pick it up, rebase it on the current master and fix the build.

ulrichb avatar Jun 29 '21 09:06 ulrichb