Handling disconnect on remote server

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
j_smart
Posts: 3
Joined: Mon 23 May 2016 03:51

Handling disconnect on remote server

Post by j_smart » Mon 13 Jun 2016 06:29

Hi

What is the best way to handle the situation where I have a client/server connection to a remote server and the remote server disconnects the client while it's still connected?

eg assuming a standard client/server connection to a remote server and on the remote server the firebird service itself is restarted while a client is still connected - Select queries may be open and one or more transactions are active.

When the client attempts to next read/write to the database various errors (EIBCError) are raised but mainly ErrorCode -902 with either ErrorNumber 335544726 or 335544727.

I have pooling set to True. Ideally I would like to simply re-establish the same connection again (since the service is back up and running) but this is proving more difficult than first thought. The OnConnectionLost event doesn't seem to fire in these instances (I'm assuming because it's a remote connection).

In the OnError event of the TIBCConnection component, I've tried:

Code: Select all

 
  if (E.ErrorCode = -901) or ((E.ErrorCode = -902) and (EIBCError(E).ErrorNumber = 335544726) or (EIBCError(E).ErrorNumber = 335544727) ) then
  begin
   ActiveDS := TList<TDataSet>.Create;
    try
      for j := 0 to Connection.DataSetCount-1 do
        if (Connection.DataSets[j] is TCustomDADataSet) and (TCustomDADataSet(Connection.DataSets[j]).Active) then
          ActiveDS.Add(Connection.DataSets[j]);

      try
        Connection.RemoveFromPool;
        Connection.Disconnect;
      except
      end;

      IBConnection.Connect;
      // reopen any active datasets that will have been closed when we called Disconnect above
      for j := 0 to ActiveDS.Count-1 do
      begin
        DS := ActiveDS[j];
        if not DS.Active then
          DS.Open;

      end;

    finally
      ActiveDS.Free;
    end;
end;
This kinda works, but isn't great.

Any advice appreciated.

Thanks

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Handling disconnect on remote server

Post by ViktorV » Wed 15 Jun 2016 14:04

We will change this behavior of IBDAC in the next build. From now, when ErrorNumber 335544726 or 335544727 occurs, the OnConnectionLost event will be triggered.

j_smart
Posts: 3
Joined: Mon 23 May 2016 03:51

Re: Handling disconnect on remote server

Post by j_smart » Wed 15 Jun 2016 22:33

Awesome.

Thanks very much!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Handling disconnect on remote server

Post by ViktorV » Thu 10 Nov 2016 15:05

The new IBDAC version with improved OnConnectionLost event of the Connection component is available for download now.

Post Reply