473,467 Members | 1,962 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Transaction on functions

Hi,
Suppose I have four different functions. All four update four
different tables. I want to execute these functions in a transaction.

TRANSACTION START
CALL A=FUNCTION1()
CALL B=FUNCTION2()
CALL C=FUNCTION3()
CALL D=FUNCTION4()
TRANSACTION END

Is it possible to do?

Thanks
Mukesh

May 16 '06 #1
4 1328
Yup; old-school way is to pass an ADO.Net transaction (IDbTransaction) to
each method and have them enlist; a pain.
A more convenient way (in 2.0) is to use TransactionScope (refer to MSDN2),
which creates an ambient transaction; you use ("using") the transaction
scope around the 4 calls, and the ADO.Net calls enlist automatically; then
you commit. If an exception happens, then typically the scope is disposed
without commit, and so is rolled back.

Basically it is DTC without the overhead of COM+/MTS. Very tidy. Of course,
it needs DTC running, so not reliable on a client, but very handy at the
server. It also works best on SqlServer 2005 as it can then use promoteable
transactions - i.e. they start out as ADO.Net transactions, then become DTC
transactions if (and only if) a second server gets involved. With SqlServer
2000 it panics and jumps straight to DTC.

Hope this helps,

Marc
May 16 '06 #2
"mukesh" <cm*******@gmail.com> wrote:
Suppose I have four different functions. All four update four
different tables. I want to execute these functions in a transaction.

TRANSACTION START
CALL A=FUNCTION1()
CALL B=FUNCTION2()
CALL C=FUNCTION3()
CALL D=FUNCTION4()
TRANSACTION END


In C#:

---8<---
using (TransactionScope scope = new TransactionScope())
{
Function1();
Function2();
Function3();
Function4();
scope.Complete();
}
--->8---

-- Barry
May 16 '06 #3
Hi,
Thanks it works. Is there any way to do the same in .NET 1.1
framework?

Thanks
Mukesh

May 17 '06 #4
"mukesh" <cm*******@gmail.com> wrote:
Thanks it works. Is there any way to do the same in .NET 1.1
framework?


See the other poster. It's more awkward in .NET 1.1.

-- Barry
May 17 '06 #5

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

Similar topics

7
by: Abdul-Wahid Paterson | last post by:
Hi, I have had a site working for the last 2 years and have had no problems until at the weekend I replace my database server with a newer one. The database migration went like a dream and I had...
12
by: John Sidney-Woollett | last post by:
I have to convert an java web application currently using an Oracle DB back end to one using a Postgres backend. In Oracle much of the application logic is abstracted away from the java...
3
by: Andrew Chanter | last post by:
I have a long and complex data manipulation algorithm written in ADO that performs about 20 different data manipulation processes sequentially. I intend to finalise this function (lets call it...
3
by: Hardy Wang | last post by:
Hi all, I have an application, which requires several SQL activities, so I wrap them in a transaction: SqlConnection conn = new SqlConnection(connectionString); conn.Open(); SqlTransaction tran...
1
by: REB | last post by:
If I create a transaction object for rolling back a insert query in the on click event of a form button can the transaction be tracked across other functions? For example: private void...
1
by: Thapliyal, Deepak | last post by:
Can I use a "set transaction" type mechanism within a function? thx Deep -----Original Message----- From: Joshua D. Drake Sent: Tuesday, January 13, 2004 10:17 AM To: Thapliyal, Deepak...
2
by: Pascal Polleunus | last post by:
(another try with a different subject as it doesn't seem to work with "EXECUTE + transaction = unexpected error -8" :-/) Hi, It seems that there is a problem when executing a dynamic...
2
by: Phil Endecott | last post by:
Dear All, Within a transaction, now() and current_timestamp are constant and give the time that the transaction started. This is normally what you want. But I have a case where I actually need...
2
by: Dan Kelley | last post by:
I have 2 services, ServiceA and ServiceB. Certain user driven functions require ServiceA to perform some DB tasks, before sending a request to ServiceB to perform some additional tasks. If ServiceB...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.