Transactions Error: DEF_TRANS_KEY has not been started


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
The docs are a little ambiguous on this issue (see Using Transactional Processing); however, it appears that only one DB is involved per transaction.  I am formulating this conclusion from the fact that a datasourcekey is passed to the transaction methods.  So, I will need to be a bit creative in order to get two transactions going...if the second gets rolledback, then the first must be rolledback, too.

In my simplified/summarized/clipped code, I was thinking of doing something like this:

private void UpdateFirstDB()
{
   
try
   
{
   
BusinessLayer.TransactionBegin(MyPrimaryBO.DataSourceKey, IsolationLevel.ReadCommitted);
    . . . do some processing on a bunch of BOs in the primary data source . . .
    UpdateSecondDB();
   
BusinessLayer.TransactionCommit(MyPrimaryBO.DataSourceKey);
    }
   
catch
   
{
       
BusinessLayer.TransactionRollback(MyPrimaryBO.DataSourceKey);
       
throw;
    }
}

The secondary transaction looks quite similar:

private void UpdateSecondDB()
{
   
try
   
{
   
BusinessLayer.TransactionBegin(MySecondaryBO.DataSourceKey, IsolationLevel.ReadCommitted);
    . . . do some processing on a bunch of BOs in the secondary data source . . .
   
BusinessLayer.TransactionCommit(MySecondaryBO.DataSourceKey);
    }
   
catch
   
{
       
BusinessLayer.TransactionRollback(MySecondaryBO.DataSourceKey);
       
throw;
    }
}

Since the second transaction is wrapped inside the first, then any errors from the second should 1) Rollback the second transaction; 2) Bubble up the error which is caught inside the first transaction; 3) Rollback the first transaction; 4) Run my unhandled exception routine.

Am I thinking clearly enough on this?
Bill


Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)StrataFrame VIP (1.1K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
So far, the testing has gone quite well with this new code.  If anyone can see where I need improvements, please let me know.  Otherwise, I am running with this.

Thanks!
Bill

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search