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;
Any advice appreciated.
Thanks