467,188 Members | 1,434 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,188 developers. It's quick & easy.

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
  • viewed: 1092
Share:
4 Replies
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by BC | last post: by
4 posts views Thread by Charles Law | last post: by
1 post views Thread by Manu Singhal | last post: by
3 posts views Thread by =?Utf-8?B?Ulc=?= | last post: by
3 posts views Thread by Rahul Babbar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.