0 Replies Latest reply: Sep 11, 2012 7:27 AM by 961365 RSS

    Committing/Rolling Back a Dequeue from C#

    961365
      I have a C# solution which is successfully subscribing to and dequeuing messages from AQ, however I am now looking at tightening up the error handling and would like to ensure my dequeues are committed and rolled back when necessary. I have set the dequeue visibility property to OnCommit and want to ensure that in the event of an error in my code after dequeuing that I can roll back the entire transaction so the message isn't lost.

      Does anyone know if there is an explicit way to force a rollback? The only way I can see if by calling the Dispose() method on the OracleAQQueue object however C# code analysis tells me I should have a Dispose call along all exception paths, which means the rollback would be performed each time regardless. So I have MS best practices telling me to force a Dispose yet the desire for exception handling telling me to only do it in the exception block...

      private static void Process()
      {
      OracleConnection con = OpenConnection(myconnectionstring);
      OracleAQQueue queue = new OracleAQQueue("MyQueue", con);

      try
      {
      OracleAQMessage deqMsg = queue.Dequeue(myOracleAQDequeueOptions);
      ...
      // Do stuff
      ...
      }
      catch (Exception ex)
      {
      queue.Dispose(); // this statement will force a rollback where I want it to happen
      }
      finally
      {
      queue.Dispose(); // but code analysis tells me I need it here, so a rollback will always happen!
      con.Dispose();
      con.Close();
      }
      }