The following code is used to reconnect the application when the connection to the server is lost:
Code: Select all
unit CRAccess;
procedure TCRConnection.DoError(E: Exception; var Fail: boolean);
...
begin
while not FInProcessError do begin
....
if Reconnect then begin
FReconnected := False;
...
try
Connect('');
FReconnected := True;
if Assigned(FOnReconnectSuccess) then
FOnReconnectSuccess;
// this function executes event OnAfterConnnect
//but if in this event any dataset is opened,
//the variable FReconnected is set as False (see code below)
//and program goes into infinite loop
except
end;
FInProcessError := False;
...
if not Reconnect or FReconnected then
break;
end;
end;Code: Select all
unit MyAccess;
procedure TCustomMyDataSet.InternalOpen;
begin
TMySQLConnection(TDBAccessUtils.GetIConnection(UsedConnection)).Reconnected := False; /// CR 20648
inherited;
end;