Lost connection and Reconnect loop

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
sjone
Posts: 2
Joined: Tue 27 Apr 2010 11:13

Lost connection and Reconnect loop

Post by sjone » Tue 27 Apr 2010 12:12

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?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 28 Apr 2010 07:21

Thank you for information. We have reproduced this problem and fixed it. This fix will be included in the next MyDAC build.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 28 Apr 2010 07:23

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; 

sjone
Posts: 2
Joined: Tue 27 Apr 2010 11:13

Post by sjone » Wed 28 Apr 2010 09:22

Thank you for your quick response :)

Post Reply