|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to raise an event when a transaction is rollbackedHello,
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 Graphix,
Why not just make a module or a shared class from which you can call the method? Cor Show quoteHide quote "graphicsxp" <samuelberthe***@googlemail.com> schreef in bericht news:1155032988.782234.143210@h48g2000cwc.googlegroups.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 > 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: Show quoteHide quote > Graphix, > > Why not just make a module or a shared class from which you can call the > method? > > Cor > > "graphicsxp" <samuelberthe***@googlemail.com> schreef in bericht > news:1155032988.782234.143210@h48g2000cwc.googlegroups.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 > > 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. Show quoteHide quote "graphicsxp" <samuelberthe***@googlemail.com> wrote in message news:1155040679.362504.164100@i42g2000cwa.googlegroups.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" <samuelberthe***@googlemail.com> schreef in bericht >> news:1155032988.782234.143210@h48g2000cwc.googlegroups.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 >> > > 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, |
|||||||||||||||||||||||