Page 1 of 1
Connection Lost events
Posted: Tue 13 Jul 2010 15:21
by maciejmt
I would like create own procedure of reconnect to MySQL server.
For test, I put:
in event OnConnectionLost of TMyConnection (also in AfterDisconnect).
Next, In services, I stopped MySQL service and showmessage doesn't appear.
Why ?
Posted: Tue 13 Jul 2010 15:51
by Challenger
Please try to set the LocalFailover property to true.
Posted: Tue 13 Jul 2010 16:06
by maciejmt
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;
Posted: Wed 14 Jul 2010 02:00
by eduardosic
Set MyConnection.Options.LocalFailOver := True
and use the OnConnectionLost Event.
Posted: Wed 14 Jul 2010 05:27
by maciejmt
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
Posted: Wed 14 Jul 2010 05:34
by eduardosic
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.
Posted: Wed 14 Jul 2010 09:07
by Challenger
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.
Posted: Wed 14 Jul 2010 13:36
by maciejmt
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.
Posted: Mon 19 Jul 2010 10:27
by Dimon
If your code worked in a desktop application, it should work in a service application as well.