Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 1 of 1 total
Thread When does a transaction try to apply a lock??
Wed, Mar 29 2023 12:35 AMPermanent Link

Ian Branch

Avatar

Hi Team,
I have this basic code..
{code}
 //
 SetLength(aTablesArray, 5);
 //
 aTablesArray[0] := 'LineItems';
 aTablesArray[1] := 'Parts';
 aTablesArray[2] := 'BackOrders';
 aTablesArray[3] := 'JobTickets';
 aTablesArray[4] := 'APJobTickets';
 //
 dmS.DBC1.StartTransaction(aTablesArray);
 //
 try
   LogMessage(' - In the Transaction');
   JobTickets.Edit;
   LineItems.Edit;
   Parts.Edit;
   //
   {$IFDEF SILogging}
   LogMessage('..Qty Needed = ' + nQtyNeeded.ToString);
   LogMessage('..Wty Parts - WtyQty = ' + Parts.FieldByName('WtyQty').AsString);
   LogMessage('..Coy Parts - CoyQty = ' + Parts.FieldByName('CoyQty').AsString);
   {$ENDIF}
   //
   Blah..
   Blah..
   Blah..
   //
   /// //////////////////////////////////////////////////////////////////////////////
   /// Finish Transaction here
   /// /////////////////////////////////////////////////////////////////////////////
   //
   dmS.DBC1.Commit;
   //
 except
   //
   on E: Exception do
   begin
     if (E is EDatabaseError) and (E is EEDBError) then
     begin
       //
       var sTable: string;
       //
       if ContainsText(EEDBError(E).ErrorMsg, 'LineItems') then sTable := 'LineItems';
       if ContainsText(EEDBError(E).ErrorMsg, 'Parts') then sTable := 'Parts';
       if ContainsText(EEDBError(E).ErrorMsg, 'BackOrders') then sTable := 'BackOrders';
       if ContainsText(EEDBError(E).ErrorMsg, 'JobTickets') then sTable := 'JobTickets';
       if ContainsText(EEDBError(E).ErrorMsg, 'APJobTickets') then sTable := 'APJobTickets';
       //
       if (EEDBError(E).ErrorCode = EDB_ERROR_LOCK) then
         TaskMessageDlg('Possible record lock in place!', 'Unable to process the part for the Job Ticket at this time.' + sLineBreak +
           'Another application may have one or more relevant records open in the ' + sTable + ' table for editing at this time.' + sLineBreak +
           'Please retry a little later.', mtError, [mbOK], 0)
       else
         ShowMessage('Unknown or unexpected database engine error # ' + IntToStr(EEDBError(E).ErrorCode) + ' - ' + EEDBError(E).ErrorMsg);
     end
     else
       ShowMessage('Unknown or unexpected error has occurred');
     //
     dmS.DBC1.RollBack;
     LineItems.Refresh;
     //
   end;
   //
 end;
 //
{code}

At what point does the transaction try to put a lock on the table??
The reason for the question is that with this in place, the User got a "ElevateDB Error #300 Cannot lock the table Parts in the schema Default for transaction access." error.
I am unsure if this was at the point of StartTransaction, or, when trying to set the Parts table to edit.
Note - The "    LogMessage(' - In the Transaction');" was not logged.

Regards,
Ian
Image