StartTransaction giving Error " Already in Transaction " .

I am doing  a 3 tier application on Delphi(MIDAS) with MSSql as backend. I would like to insert/update and edit the datas of master and detail tables with an active transaction ,so that i can commit or rollback, if there is any error.

I have written in the after post event the following code.

   DataModule.SockectConnection.AppServer.StartTransaction;
   { this is a TLB Method that checks if any transaction is active and if not Starts a new Transaction " if not DataBase.InTransaction then DataBase.StartTransaction;" }
   try
    ClientDataSet_Master.ApplyUpdates(-1);
    ClientDataSet_Detail.ApplyUpdates(-1);
    DataModule.SockectConnection.AppServer.Commit;
    { this is a TLB Method that checks if any transaction is active and if Commits the active transaction " if DataBase.InTransaction then DataBase.Commit;"}
   except
    DataModule.SockectConnection.AppServer.Rollback;
    { this is a TLB Method that checks if any transaction is active and if Rollbacks the active transaction " if DataBase.InTransaction then DataBase.Rollback;"}  
   end;
                    But it gives an error 'Already InTrasaction ' when the control goes to  the line
     ClientDataSet_Master.ApplyUpdates(-1);

   What might be the problem ? Is it due to the back-end (MSSQL ) that has a default Transaction ??
vineeth_mathewAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
nafeelmConnect With a Mentor Commented:

try setting the StatTransaction in Before Post event

in the AfterPost event let the following be:
  try
   //ClientDataSet_Master.ApplyUpdates(-1); you cannot put this here
   ClientDataSet_Detail.ApplyUpdates(-1);
   DataModule.SockectConnection.AppServer.Commit;
  except
   DataModule.SockectConnection.AppServer.Rollback;
  end;

also set the RollBack event in AfterCancel event just incase the user cancels the record!
0
 
CleanupPingCommented:
vineeth_mathew:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
All Courses

From novice to tech pro — start learning today.