473,466 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to raise an event when a transaction is rollbacked

Hello,

I've got a few stored procedure called made within one sqlTransaction
object.

If the .Rollback() method of the transaction is called, then I would
like some extra code to be executed. The issue is that the .Rollback()
method can be called from many different places so I don't want to
write this code in all those places. Therefore how can I add an event
handler to this method, so that each time it is called, an event is
raised, which will then execute my code ?

Thank you

Aug 8 '06 #1
4 1248
Graphix,

Why not just make a module or a shared class from which you can call the
method?

Cor

"graphicsxp" <sa*************@googlemail.comschreef in bericht
news:11**********************@h48g2000cwc.googlegr oups.com...
Hello,

I've got a few stored procedure called made within one sqlTransaction
object.

If the .Rollback() method of the transaction is called, then I would
like some extra code to be executed. The issue is that the .Rollback()
method can be called from many different places so I don't want to
write this code in all those places. Therefore how can I add an event
handler to this method, so that each time it is called, an event is
raised, which will then execute my code ?

Thank you

Aug 8 '06 #2
I suppose I could do that... but I thought raising an event sounds
better, i don't have to share anything then.
Cor Ligthert [MVP] wrote:
Graphix,

Why not just make a module or a shared class from which you can call the
method?

Cor

"graphicsxp" <sa*************@googlemail.comschreef in bericht
news:11**********************@h48g2000cwc.googlegr oups.com...
Hello,

I've got a few stored procedure called made within one sqlTransaction
object.

If the .Rollback() method of the transaction is called, then I would
like some extra code to be executed. The issue is that the .Rollback()
method can be called from many different places so I don't want to
write this code in all those places. Therefore how can I add an event
handler to this method, so that each time it is called, an event is
raised, which will then execute my code ?

Thank you
Aug 8 '06 #3

How about ... extending the sqlTransaction object and create you own ...

- inherit from the sqlTransaction object...
- mySqlTransaction Object ...
- add you event there ... myRollBackExtended ...
- If you can, Override the .Rollback and include your raiseent here ...
- If you can not override the .Rollback, create you own .MyRollBack and us
it (this would required you to replace the .Rollback call with myRollback
call ... global / find and replace) ...

Now, in your program, instead of using the sqlTransaction object, use your
MySqltransaction object ... and you will have you custom events ...

to change you code ... use the global / find and replace ...

Find ...

System.Data.SqlClient.SQLTransaction or Data.SqlClient.SQLTransaction or ...
how ever declare it...

Replace

<myproject>.<mynamespace>.mySqltransaction

Sorry this does not work ... sqlTransaction is non-inheritable (do not know
why) ... should have checked before I wrote a response ... too bad ...

However, all is not lost, you could wrap the sqlTransaction in your own
object ... with sqlTransaction as a property / member ... and use your
custom object to extend the rollback functionality... basically, this wold
be a little 'overhead' up front (programming), but it will allow you to
'customize' or 'extend' the functionality of the sqlTransaction object ...
and will put all your code in one place ... and not spreadout over a few
modules or shared classes ... This design allow you to 'reliably' capture
those instances when you need to 'extend' the rollback, without having to
remember to 'include a call another shared class event'...

Jeff.

"graphicsxp" <sa*************@googlemail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
>I suppose I could do that... but I thought raising an event sounds
better, i don't have to share anything then.
Cor Ligthert [MVP] wrote:
>Graphix,

Why not just make a module or a shared class from which you can call the
method?

Cor

"graphicsxp" <sa*************@googlemail.comschreef in bericht
news:11**********************@h48g2000cwc.googleg roups.com...
Hello,

I've got a few stored procedure called made within one sqlTransaction
object.

If the .Rollback() method of the transaction is called, then I would
like some extra code to be executed. The issue is that the .Rollback()
method can be called from many different places so I don't want to
write this code in all those places. Therefore how can I add an event
handler to this method, so that each time it is called, an event is
raised, which will then execute my code ?

Thank you

Aug 8 '06 #4
Hi Jeff,
thanks for the long reply. Actually I've opted for the second solution
you offered (to wrap the SQLTransac object) and that works fine.
thanks again,

Aug 9 '06 #5

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

Similar topics

1
by: Dan Cimpoiesu | last post by:
I have a remoting object, derived from MarshalByRefComponent, that I instantiate on the client side, with Activator.GetObject. Can I receive events fired on the server, on the client? How?
1
by: BC | last post by:
Hi all, I have two classes: TransactionCollection and Transaction, where TransactionCollection is used to store Transaction objects. public class TransactionCollection : CollectionBase {...
4
by: Charles Law | last post by:
Suppose a worker thread needs to signal to the main thread that an event has occurred. Ordinarily, any event raised by the worker thread will be on its own thread. How can the worker thread...
3
by: moondaddy | last post by:
I wrote my own List class which I use to bind to list controls. this class inherits CollectionBase and implements IBindingList. This class contains a list of business classes such as customers...
1
by: Anonieko | last post by:
I know Visual Studio lacked support on easily writing code to raise events from a ascx user control ( because you have to hand write them)....
1
by: Manu Singhal | last post by:
Hi I want to know how can one use TransactionScope with the CreateUserWizard Contrrol I have to update a Table in my database if the user is created But if i fail to update the Table the...
3
by: =?Utf-8?B?Ulc=?= | last post by:
I constructed a new Class with some private members. I would like an event to be raised on the moment the value of one of those private members is changed. How do I define an event for that...
5
by: Mike | last post by:
Hi group; Let say I have an object called Account, that raises an event called AccountLow with its owns EventArgs, and when this event gets raised, I will like to raise another custom...
3
by: Rahul Babbar | last post by:
Hi All, When could be the possible reasons that could make a database inconsistent? I was told by somebody that it could become inconsistent if you " force all the applications to a close on...
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:
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...
1
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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: 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.