Transactions Error: DEF_TRANS_KEY has not been started


Author
Message
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
Here is my code:

private void UpdateAspireForTransfer()
{
    try
    {
       
BusinessLayer.TransactionBegin("Aspire", IsolationLevel.ReadCommitted);
       
// Retrieve the next Batch ID
       
String mBatchID = GetNextBatchID();
        AssignBatchID(mBatchID);
        CreateCommissions(mBatchID);
       
BusinessLayer.TransactionCommit("Aspire");
        UpdateDynamicsForTransfer(mBatchID);
    }
    catch
    {
       
BusinessLayer.TransactionRollback("Aspire");
       
throw;
    }
}

For some reason, yet unknown to me, the TransactionRollBack gets called and generates an error:

A transaction with the key [DEF_TRANS_KEY] has not been started.

and this stack trace:

at MicroFour.StrataFrame.Data.DbDataSourceItem.TransactionEnd(String TransactionKey, Boolean IsCommit)
at MicroFour.StrataFrame.Data.DbDataSourceItem.TransactionRollback(String TransactionKey)
at MicroFour.StrataFrame.Business.BusinessLayer.TransactionRollback(String DataSourceKey)
at Aspire.Accounting.Invoicing.UpdateAspireForTransfer()
at Aspire.Accounting.Invoicing.TransferTSB_Click(Object sender, EventArgs e)
at System.Windows.Forms.ToolStripItem.RaiseEvent(Object key, EventArgs e)
at System.Windows.Forms.ToolStripButton.OnClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
at System.Windows.Forms.ToolStripItem.FireEventInteractive(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStripItem.FireEvent(EventArgs e, ToolStripItemEventType met)
at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ToolStrip.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativewindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

So, what am I doing wrong?

Thanks, for straightening me out,
Bill


Replies
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)
Group: Forum Members
Posts: 785, Visits: 3.6K
As I am re-working the transaction thingy, I was wondering, can one transaction cover data changes on two different databases?
Bill Cunnien
Bill Cunnien
StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K reputation)StrataFrame VIP (1.2K 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


GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Threaded View
Threaded View
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago
StrataFrame Team - 17 Years Ago
Bill Cunnien - 17 Years Ago
                         Still not working. A transaction with the key [DEF_TRANS_KEY] has not...
Bill Cunnien - 17 Years Ago
                             I am removing transactions within the code. This would be a perfect...
Bill Cunnien - 17 Years Ago
                                 Transactions are a commonly used portion of the framework, but the one...
Trent L. Taylor - 17 Years Ago
                                     Ok, now that Edhy helped me solve an underlying issue with the primary...
Bill Cunnien - 17 Years Ago
                                         As I am re-working the transaction thingy, I was wondering, can one...
Bill Cunnien - 17 Years Ago
                                             The docs are a little ambiguous on this issue (see Using Transactional...
Bill Cunnien - 17 Years Ago
Bill Cunnien - 17 Years Ago

Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search