Page 1 of 1

Handling disconnect on remote server

Posted: Mon 13 Jun 2016 06:29
by j_smart
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

Re: Handling disconnect on remote server

Posted: Wed 15 Jun 2016 14:04
by ViktorV
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.

Re: Handling disconnect on remote server

Posted: Wed 15 Jun 2016 22:33
by j_smart
Awesome.

Thanks very much!

Re: Handling disconnect on remote server

Posted: Thu 10 Nov 2016 15:05
by ViktorV
The new IBDAC version with improved OnConnectionLost event of the Connection component is available for download now.