Not writing to database

I have some updating code in a thread that updates the progress of a background job:

  if FCurrentStep mod FUpdateStep = 0 then
  begin
    FJob.Progress :=  RoundTo(FCurrentStep / FTotalSteps * 100, -2);
    FObjectManager.Update(FJob);
    FObjectManager.Flush(FJob);
  end;

The code does get called, but the data does not get updated in the table. Any ideas? thanks.

Hi Russell,
Are you getting a proper DBConnection and manager within your thread?

var
  Manager: TObjectManager;
  DBConnection: IDBConnection;
begin
  FObjectManager := nil;
  try
    DBConnection := YourServerModule.AureliusConnection.CreateConnection;
    FObjectManager := TObjectManager.Create(DBConnection);
    try
	  if FCurrentStep mod FUpdateStep = 0 then
	  begin
        FJob.Progress :=  RoundTo(FCurrentStep / FTotalSteps * 100, -2);
        FObjectManager.Update(FJob);
        FObjectManager.Flush(FJob);
      end;
    end;
  finally
    FObjectManager.Free;
  end;
end;

Yes, I think so, it writes out at some point, possibly when the manager is released. It only seems to be this bit that doesn't work.

FDBConnection := ServerContainer.GetPooledConnection;

FObjectManager := TObjectManager.Create(DBConnection);
function TServerContainer.GetPooledConnection: IDBConnection;
begin
  Result := XDataConnectionPool.GetPoolInterface.GetConnection;
end;

Was FJob object fetched from FObjectManager within the thread? Or is it a trancient object which is more likely since you call FObjectManager.Update(FJob) before Flush.

It is called from the same object manager and maintained while the job processes.

In this case Update call is not needed. Flush should be enough. But it should work, there is nothing unusual here. Have you debugged it? Are you sure the code is reaching that line of code? Do you have an open transaction and are you committing the transaction eventually?

I have stepped through and it is being called. I haven't specifically opened a transaction, just relying on the object manager.

I'm afraid we will need a sample reproducing the problem, as I'm running out of ideas here. Could you please send it?

I'll try and step right through it and into the aurelius code. Putting together a sample would probably take an age

1 Like

Russell
Are you using Aurelius event callbacks/hooks they may provide some useful logs for the lifespan of your FJob.

good shout. I'm not using them, but I'll try that

stepped through and it fires this statement

function TFireDacStatementAdapter.Execute: Integer;
begin
  if FADQuery = nil then Exit(0);
  FADQuery.ExecSQL;
  Result := FADQuery.RowsAffected;
end;

and RowsAffected = 1

strange, as if the Transaction is not committed.

But fascinating stepping through the code.

1 Like