Connection Lost events

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
maciejmt
Posts: 27
Joined: Sun 25 Apr 2010 14:14

Connection Lost events

Post by maciejmt » Tue 13 Jul 2010 15:21

I would like create own procedure of reconnect to MySQL server.

For test, I put:

Code: Select all

showmessage('test');
in event OnConnectionLost of TMyConnection (also in AfterDisconnect).

Next, In services, I stopped MySQL service and showmessage doesn't appear.

Why ?

Challenger
Devart Team
Posts: 925
Joined: Thu 17 Nov 2005 10:53

Post by Challenger » Tue 13 Jul 2010 15:51

Please try to set the LocalFailover property to true.

maciejmt
Posts: 27
Joined: Sun 25 Apr 2010 14:14

Post by maciejmt » Tue 13 Jul 2010 16:06

Don't working...
I have MyDac 5.80 and D2009.

I click button to connect DB. Next in services stop MySQL.

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
  myconnection1.Connect;
end;

procedure TForm1.MyConnection1AfterDisconnect(Sender: TObject);
begin
  showmessage('test');
end;

procedure TForm1.MyConnection1ConnectionLost(Sender: TObject;
  Component: TComponent; ConnLostCause: TConnLostCause;
  var RetryMode: TRetryMode);
begin
  showmessage('test');
end;

procedure TForm1.MyConnection1Error(Sender: TObject; E: EDAError;
  var Fail: Boolean);
begin
  showmessage('test');
end;

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Post by eduardosic » Wed 14 Jul 2010 02:00

Set MyConnection.Options.LocalFailOver := True
and use the OnConnectionLost Event.

maciejmt
Posts: 27
Joined: Sun 25 Apr 2010 14:14

Post by maciejmt » Wed 14 Jul 2010 05:27

eduardosic wrote:Set MyConnection.Options.LocalFailOver := True
and use the OnConnectionLost Event.
In your work?

1. I set LocalFailOver := True
2.

Code: Select all

procedure TForm1.MyConnection1ConnectionLost(Sender: TObject;
  Component: TComponent; ConnLostCause: TConnLostCause;
  var RetryMode: TRetryMode);
begin
  showmessage('test');
end;
3. connect to DB
4. Stop MySQL service
5. Nothing happened
6. Click button

Code: Select all

  if myconnection1.Connected then
    showmessage('why connected ?');
(dialog appears)
7. MySQL administrator log
C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld: Forcing close of thread 4 user: 'xx'


C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld: Forcing close of thread 3 user: 'xx'


C:\Program Files\MySQL\MySQL Server 5.1\bin\mysqld: Forcing close of thread 1 user: 'xx'
8. D2009 + MyDAC v5.80.0.47
Last edited by maciejmt on Wed 14 Jul 2010 05:36, edited 2 times in total.

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Post by eduardosic » Wed 14 Jul 2010 05:34

try this.

Put a TMyQuery linked with a TMyConnection and execute this..

Code: Select all

    MyConnection.Connect;
    ShowMessage( 'Please, stop MySQL Server and press OK to continue.' );
    MyQuery.Close;
    MyQuery.SQL.Text := 'Select Version()' ;
    MyQuery.Execute; // Ok on this point. LostConnection is called.. 
    //Lost Connection Happen when yoy try a comunication with server.
remember, you can set RetryMode in onConnectionLost Event

RetryMode := rmReconnectExecute;

Please, see Mydac Demo
C:\Users\Public\Documents\Devart\MyDac for RAD Studio 2007\Demos\Win32\Miscellaneous\FailOver

And Upgrade the Mydac to the Last Version.

Challenger
Devart Team
Posts: 925
Joined: Thu 17 Nov 2005 10:53

Post by Challenger » Wed 14 Jul 2010 09:07

To eduardosic:
Thanks for the sample.

To maciejmt:
The connection lost will be detected on the first database operation. So you should execute any statement and then this event will be raised.

maciejmt
Posts: 27
Joined: Sun 25 Apr 2010 14:14

Post by maciejmt » Wed 14 Jul 2010 13:36

thx !

In this case, Showmessage falls into infinity loop.

Code: Select all

procedure TForm1.MyConnection1ConnectionLost(Sender: TObject;
  Component: TComponent; ConnLostCause: TConnLostCause;
  var RetryMode: TRetryMode);
begin
  showmessage('t');
end;

Here is OK, but is throwing exception.
I want use this code in serviceapp.
It will be OK ?

Code: Select all

procedure TForm1.MyConnection1ConnectionLost(Sender: TObject;
  Component: TComponent; ConnLostCause: TConnLostCause;
  var RetryMode: TRetryMode);
begin
  RetryMode := rmRaise;
  //Own procedure of reconnect
end;
RetryMode.rmReconnect is bad, I noticed that application is 'freezing', when stopped MySQL.

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

Post by Dimon » Mon 19 Jul 2010 10:27

If your code worked in a desktop application, it should work in a service application as well.

Post Reply