Passing DBTransaction between functions in Bus Layer

  • Thread starter Thread starter Chevron Boyde
  • Start date Start date
C

Chevron Boyde

Hi all

I have a function setup in my Bus Logic Layer similar to the following
function ProcessOrders
function InsertOrder
function InsertOrderItems

I need to be make sure all functions use the same Transaction (Enterprise
Lib DbTransaction object) between method calls.

How shoudl I lat this out?

Cheers

S
 
The most practial solution would be TransactionScope; apart from not
requiring any work, any other code that uses suitable connections can
also enlist, it supports distributed transactions, and nesting is
supported (as are isolation levels, non-transactional blocks, etc).

Example: add a reference to System.Transactions, then

// cheesy example ;-p
static void Transfer(int fromAccount, int toAccount, int amount)
{
using (TransactionScope tran = new TransactionScope())
{
Debit(fromAccount, amount);
Credit(toAccount, amount);
tran.Complete();
}
}

On SQL2000, it uses DTC from the outset (since SQL2000 transactions
aren't promoteable) - but on SQL2005 it uses the "LTM" (lightweight
transaction manager) to start with a SQL transaction, and promote that
to a DTC transaction if necessary (for instance you start talking to a
second server...).

Marc
 
Back
Top