473,581 Members | 2,755 Online
Bytes | Software Development & Data Engineering Community
+ 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 1267
Graphix,

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

Cor

"graphicsxp " <sa************ *@googlemail.co mschreef in bericht
news:11******** **************@ h48g2000cwc.goo glegroups.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.co mschreef in bericht
news:11******** **************@ h48g2000cwc.goo glegroups.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...
- mySqlTransactio n Object ...
- add you event there ... myRollBackExten ded ...
- 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
MySqltransactio n object ... and you will have you custom events ...

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

Find ...

System.Data.Sql Client.SQLTrans action or Data.SqlClient. SQLTransaction or ...
how ever declare it...

Replace

<myproject>.<my namespace>.mySq ltransaction

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.co mwrote in message
news:11******** **************@ i42g2000cwa.goo glegroups.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.co mschreef in bericht
news:11******* *************** @h48g2000cwc.go oglegroups.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
10504
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
2019
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 { public TransactionCollection() { }
4
9806
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 raise an event on the main thread instead? TIA Charles
3
2113
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 for example. In the customer class I have an event called MyTestEvent and when certain conditions arise, I want to raise this event which would...
1
9932
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). (http://codebetter.com/blogs/brendan.tompkins/archive/2004/10/06/27795.aspx) Question: Is it better and easier now in ASPNET 2.0 , meaning VS 2005?
1
1312
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 Created USer shopuld be rollbacked..
3
2121
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 private member and how do I raise the event? -- RW
5
1999
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 event called AccountGotLowAmount and passes AccountLow’s EventArgs along with the new event.
3
6176
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 that database and transactions are not committed or rollbacked" I infact, don't believe it, because i suppose when we do a "force
0
8134
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8296
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7880
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6539
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5350
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3794
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3807
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2295
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 we have to send another system
1
1394
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.