Subject Transaction started issue - How is this possible?
Author Joe
I have the following piece of code:

debugmsg("Starting Transaction if necessary", true);
if (!ScratchTransaction->Started)
{
debugmsg("Transaction not started, so starting it.", true);
ScratchTransaction->StartTransaction();
}
else
{
debugmsg("Transaction was already started, so NOT starting it.", true);
}
debugmsg("Done with Transaction starting stuff.", true);

ScratchTransaction is a TIB_Transaction. "debugmsg" is just my own function that writes messages to a log file.

What happens is that the "Starting Transaction if necessary", and then the "Transaction not started, so starting it." messages appear in the log. The user then gets an exception, saying, "The transaction has already been started.".

The "Done with Transaction starting stuff." message never makes it into the log, so I can tell that it's the ScratchTransaction->StartTransaction() that is raising the exception.

How can the transaction already be started if I JUST verified that ScratchTransaction->Started is returning False? Is there something else I should be testing for, other than ScratchTransaction->Started?

This is an intermittent problem. It works fine most of the time, but once in a while this happens. And once it happens, it will keep happening until they close the application and restart it.

-Joe