Transaction processing strange behavior


Author
Message
Marcel Heitlager
Marcel Heitlager
StrataFrame User (276 reputation)StrataFrame User (276 reputation)StrataFrame User (276 reputation)StrataFrame User (276 reputation)StrataFrame User (276 reputation)StrataFrame User (276 reputation)StrataFrame User (276 reputation)StrataFrame User (276 reputation)StrataFrame User (276 reputation)
Group: StrataFrame Users
Posts: 84, Visits: 835
Hi,

For some reason when I try to save data to two tables during a transaction save, sometimes the transaction only commits one of the tables. This is on a website. It happens when a person might put a payment through and the entire transaction fails, and rolls back for some reason.   Then the person will try it again within a couple of minutes, and the transaction only commits the data to the 2nd save.  See below:


        '-- first generate a unique transaction key
        Dim lcTransactionKey As String = AES.BOL.Base.Utils.NewSeqGuid().ToString

        Try
            TransactionBegin(Me.OPPaymentDetail.DataSourceKey, lcTransactionKey, IsolationLevel.ReadCommitted)
           
            '-- First save data to the contact information table - This save Fails
            Me.OPPaymentDetail.Save(True, lcTransactionKey)
           
            '-- next get the primary key value and save to ACH detail table - This save Succeeds
            Me.OPACHInfoBO.ah_op_Key = Me.OPPaymentDetail.GetPostSavePrimaryKeyValue(-1).ToString
            Me.OPACHInfoBO.Save(True, lcTransactionKey)


            TransactionCommit(Me.OPPaymentDetail.DataSourceKey, lcTransactionKey)
 
            Return True
        Catch ex As Exception

            TransactionRollback(Me.OPPaymentDetail.DataSourceKey, lcTransactionKey)

            Me.SendTransactionReportError()
            Return False
        End Try


It seems the 2nd transaction always commits, but the first doesn't. 
It's running on SQL Server Express 2005, Windows Server 2003.  Could it be some memory cache issue?

Thanks,

Marcel
Reply
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Marcel,

Your transaction looks just fine, except that I would put a condition to the Me.OPPaymentDetail.Save() as follow:

  '-- first generate a unique transaction key
         Dim lcTransactionKey As String = AES.BOL.Base.Utils.NewSeqGuid().ToString
         Try
             TransactionBegin(Me.OPPaymentDetail.DataSourceKey, lcTransactionKey, IsolationLevel.ReadCommitted)
             '-- First save data to the contact information table - This save Fails
             If Me.OPPaymentDetail.Save(True, lcTransactionKey) = MicroFour.StrataFrame.Data.SaveUndoResult.Success Then
                 '-- next get the primary key value and save to ACH detail table - This save Succeeds
                 Me.OPACHInfoBO.ah_op_Key = Me.OPPaymentDetail.GetPostSavePrimaryKeyValue(-1).ToString
                 Me.OPACHInfoBO.Save(True, lcTransactionKey)
             End If

             TransactionCommit(Me.OPPaymentDetail.DataSourceKey, lcTransactionKey)
             Return True
         Catch ex As Exception
             TransactionRollback(Me.OPPaymentDetail.DataSourceKey, lcTransactionKey)
             Me.SendTransactionReportError()
             Return False
         End Try

Also if your transaction is failing, you are not passing the ex Exception to your Me.SendTransactionReportError() so you don't really know why it may be failing.

Edhy Rijo

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