From: JS.staff <jsp...@ec...> - 2004-02-25 16:55:14
|
Just thinking... Since it obviously essential to always communicate with FB in a transaction context (and being a good lad who always writes exception-aware code!), I found myself writing the following code a lot! : Conn.Open(); Try { FbTransaction trans =3D Conn.BeginTransaction(IsolationLevel.RepeatableRead); try { // do your stuff here trans.Commit(); } catch { trans.Rollback(); throw; } } Finally { Conn.Close(); } It seemed sensible to wrap this up, and call using a delegate from a routine such as: FbDoRoutine(fbConnection1,new FbCodeRoutine(PopulateMyGrid),IsolationLevel.RepeatableRead); PopulateMyGrid() is passed an open transaction object (plus some other info) from which it can communicate with the database. If PopulateMyGrid throws an exception, a rollback occurs, otherwise it will commit. Every time I call FB routines from an event handler, I do it by way of a call to FbCodeRoutine(). Should I need to call one handler from another, I call the delegate instead, so everything nicely happens in one transaction (unless I need otherwise, of course). Of course it does mean I have twice the number of methods in my classes! Waiting for anonymous delegates in .NET 2. If anyone wants the code, give me an email. It's only 20-30 lines, but copes with savepoints etc. John |