Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Possible to get SqlTransaction from ambient Transaction?

Due to SQL Server's SavePoints feature (SqlTransaction.Save()), I would like to use SqlTransactions in a very limited fashion (I REALLY need this functionality) while still using ambient transactions in all other places. I realize that this means that this code (and dependencies) are now SQL Server-specific - this is fine. However, I'd still prefer to follow the preferred ambient transactions in all other places for best practice purposes. (If we need to move to Oracle or something, then we'll need to rework this part of our code but don't want to rework the entire codebase.)

Is it possible to get a current SqlTransaction from Transaction.Current (which returns an object of type System.Transactions.Transaction) or some other way? (I may be wrong but I am guessing that this is ultimately the object that implements ambient Transaction object at run-time)

(related but different question I'm currently working on if you need more info on why)

like image 675
Jaxidian Avatar asked Dec 14 '25 02:12

Jaxidian


1 Answers

As far as I can tell, this simply cannot be done. Given that I'm getting no response to this, I'm marking this as the answer. I could, still, be wrong. I simply cannot figure this one out, though, and don't have the time to look into it any further.

like image 185
Jaxidian Avatar answered Dec 15 '25 17:12

Jaxidian