Page 1 of 1

[Q] Connection lost during post

Posted: 18.10.2016, 13:05
by DPStano
just want to to know how to properly handle that situation when there is connection error during applyupdates call, I thought that i can catch error reconnect and apply updates again but reconnect will close all datasets

Edit:
I can create helper to prevent dataset closing

Code: Select all

procedure TZConnectionHelper.ForceReconnect;
begin
  if FConnection <> nil then
  begin
    DoBeforeReconnect;

    ShowSqlHourGlass;
    try
      try
        FConnection.Close;
      except
        Rollback; // decrement transaction count
      end;

      FConnection.Open;
    finally
      HideSqlHourGlass;
    end;

    DoAfterReconnect;
  end;
end;

with bellow changes in unit ZDbcInterbase6

procedure TZInterbase6Connection.Close;
begin
  if Closed or (not Assigned(PlainDriver)) then
     Exit;
  try
    try
      CloseTransaction;
    except
    end;

    if FHandle <> 0 then
    begin
      GetPlainDriver.isc_detach_database(@FStatusVector, @FHandle);
      FHandle := 0;
      CheckInterbase6Error(GetPlainDriver, FStatusVector, ConSettings, lcDisconnect);
    end;
  finally
    DriverManager.LogMessage(lcConnect, ConSettings^.Protocol,
      'DISCONNECT FROM "'+ConSettings^.DataBase+'"');

    inherited Close;
  end;
end;

i can make it works but when next Connection.Disconnect is called during program shutdown im getting errors like Disconnect, Error: Error reading data from the connection., Code: -902 (Unsuccessful execution caused by a system error that precludes successful execution of subsequent statements)

Re: [Q] Connection lost during post

Posted: 24.10.2016, 20:03
by marsupilami
Hello DPStano,

I am afraid that Zeos is not built for that kind of use case. The problem here is that server ressources become invalid upon a disconnect. If you need a feature like that I would suggest to find a way to record your changes in a separate component - or maybe eben a TZQuery descandent, where you can reapply these changes after you reconnected again. Honestly my own applications simply die in a case like that...

With best regards,

Jan