Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Passing DBTransaction between functions in Bus Layer

1 view
Skip to first unread message

Chevron Boyde

unread,
May 12, 2008, 12:53:30 PM5/12/08
to
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

Marc Gravell

unread,
May 12, 2008, 4:58:38 PM5/12/08
to
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

Chevron Boyde

unread,
May 13, 2008, 2:20:56 AM5/13/08
to
thanks marc!

"Marc Gravell" <marc.g...@gmail.com> wrote in message
news:5aa8fd1e-a364-480e...@a23g2000hsc.googlegroups.com...

Marc Gravell

unread,
May 13, 2008, 3:21:05 AM5/13/08
to
No problem; for more info, there are lots of links from here:
http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx
[don't ask me why it has the same VB example twice, yet no C#]

Alternatively, just use your favorite search engine...

Marc

0 new messages