473,394 Members | 1,722 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Passing DBTransaction between functions in Bus Layer

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

Jun 27 '08 #1
3 3502
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
Jun 27 '08 #2
thanks marc!

"Marc Gravell" <ma**********@gmail.comwrote in message
news:5a**********************************@a23g2000 hsc.googlegroups.com...
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
Jun 27 '08 #3
No problem; for more info, there are lots of links from here:
http://msdn.microsoft.com/en-us/libr...tionscope.aspx
[don't ask me why it has the same VB example twice, yet no C#]

Alternatively, just use your favorite search engine...

Marc
Jun 27 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: ILLOGIC | last post by:
Hello, i am beginner in c++. I hope tobe sufficiently clear and that someone could help me on this topic. For example i have template function <typename T> T sin_func(T & x){return sin(x);} ...
7
by: Steven T. Hatton | last post by:
I am trying to convert some basic OpenGL code to an OO form. This is the C version of the program: http://www.opengl.org/resources/code/basics/redbook/double.c You can see what my current...
3
by: Steven Taylor | last post by:
Hope someone can assist. I'm trying to answer a book question. I'm going around in circles in relation to 'pointer-to-char'. Object : A short program is to be created, which involves a...
6
by: Melkor Ainur | last post by:
Hello, I'm attempting to build an interpreter for a pascal-like language. Currently, I don't generate any assembly. Instead, I just build an abstract syntax tree representing what I've parsed...
3
by: IntraRELY | last post by:
I have the following function, Notice how I am passing the dateInterval as a string. What is the correct way to pass "DateInterval.Year" as a variable to a function? TIA, Steve Wofford...
11
by: cps | last post by:
Hi, I'm a C programmer taking my first steps into the world of C++. I'm currently developing a C++ 3D graphics application using GLUT (OpenGL Utility Toolkit written in C) for the GUI...
5
by: sfeher | last post by:
Hi All, I need to call a function(loaded with appendChild) for which I have the name as a string. .... var fnName = 'fn1'; var call = fnName + '('+ param +' )'; eval(call);
3
by: waheed azad | last post by:
Hi, I have a been developing an accounting system for a non-profit organization. I had decided to to divide the solution, in three layers, presentation, business layer and database layer. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.