Page 1 of 1

Lost connection and Reconnect loop

Posted: Tue 27 Apr 2010 12:12
by sjone
Hello,

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;
This is bug or not? How fix this problem?

Posted: Wed 28 Apr 2010 07:21
by Dimon
Thank you for information. We have reproduced this problem and fixed it. This fix will be included in the next MyDAC build.

Posted: Wed 28 Apr 2010 07:23
by Dimon
As a temporary solution change the following code:

Code: Select all

        FReconnected := True; 
        if Assigned(FOnReconnectSuccess) then 
          FOnReconnectSuccess; 
to this code:

Code: Select all

        if Assigned(FOnReconnectSuccess) then 
          FOnReconnectSuccess; 
        FReconnected := True; 

Posted: Wed 28 Apr 2010 09:22
by sjone
Thank you for your quick response :)