Page 1 of 1
Check for connection and keep alive
Posted: Mon 16 Apr 2012 20:39
by classic12
Delphi XE2 update 4 latest MYdac.
I am using the MYConnection in a Indy HTTP server app.
I run a query on the OnCommandGet . ie when a request comes in.
If the connection has dropped we get an error back stating no connection but I need to ensure that if the connection has dropped it is re-connected and then run my code.
Should I set a timer to poll a table every 30 mins.
Do a reconnect on the disconnected event ??
WHat is the correct method ( and code) please.
Cheers
SteveW
Posted: Tue 17 Apr 2012 11:30
by AndreyZ
Hello,
To keep connection alive, you can ping MySQL server time after time. To ping MySQL Server, you can use the TMyConnection.Ping method that allows avoiding automatic disconnection of the client by the server.
To resume lost connection, you should use the TMyConnection.OnConnectionLost event handler. The OnConnectionLost event handler is used to process fatal errors and perform failover. To make the OnConnectionLost event handler work, you should set the TMyConnection.Options.LocalFailover property to True. Note that to use the OnConnectionLost event handler, you should add the MemData unit to the USES clause of your unit. Here is an example of using the OnConnectionLost event handler:
Code: Select all
procedure TMainForm.ButtonClick(Sender: TObject);
begin
MyConnection1.Options.LocalFailover := True;
MyConnection1.Open;
end;
procedure TMainForm.MyConnection1ConnectionLost(Sender: TObject;
Component: TComponent; ConnLostCause: TConnLostCause;
var RetryMode: TRetryMode);
begin
RetryMode := rmReconnectExecute;
end;
In this case, if connection was lost, MyDAC will try to reconnect and reexecute the abortive operation. For more information, please read the MyDAC documentation.
Posted: Thu 19 Apr 2012 13:46
by classic12
Thanks for the info. To clarify I need to set up a timer (say 1 hour) and use TMyConnection.Ping
If the connection fails it will re-open.
Is this correct ?
Cheers
SteveW
Posted: Thu 19 Apr 2012 14:12
by AndreyZ
Yes, it is correct.
error popup
Posted: Fri 20 Apr 2012 17:55
by classic12
I am getting a message box stating lost connection to MSQL. Socket error on read. WSAGetLastError return 10060(&2746).
I presume this is because I have pinged the mysql and there is no connection there until it re-connects.
How do I suppress this meesage ?
Cheers
SteveW
reply from delphi newsgroup
Posted: Mon 23 Apr 2012 21:52
by classic12
I think you are talking about DevArt DAC. And if
you configured properly automatic connection recovery,
then DAC should not give you the exception, as it
should be handled internally and recover the connection.
But if the connection is impossible to open, then still
exception may be raised.
That is IMHO. The real answer you should get from
the vendor technical support.
Any ideas?
Posted: Wed 25 Apr 2012 09:37
by AlexP
Hello,
A successfull call of the Ping method is possible only when the connection is already set. If the connection is not set, than when calling this method, an attempt to connect to a server occurs, and if the server is out-of-reach, you get a relevant error message. To suppress this message, you should wrap the Ping method with a try...except block and process the error message