OnConnectionLost on remote connect

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
Mahmood_M
Posts: 20
Joined: Thu 24 Sep 2015 21:18

OnConnectionLost on remote connect

Post by Mahmood_M » Thu 15 Oct 2015 15:23

Hi
I have a TUniConnection in my client program that connect to a remote database with IP address
I want to show a dialog if the connection lost , I have used OnConnectionLost event , but for example when I disconnect pc from Internet , the OnConnectionLost don`t occur ! ( or OnAfterDisconnect )
TUniconnection Options is :

DisconnectMode = False
AllowImplicitConnect = False
LocalFailOver = True

After disconnecting from Internet , TUniQueries are Inactive but OnConnectionLost don`t occur
It seems this event occurs only if connection get lost during a Query or Executing commands , is it True ?
How can I recognize if the connection failed ?

I`m using Delphi XE6 and MySQL
thanks

Mahmood_M
Posts: 20
Joined: Thu 24 Sep 2015 21:18

Re: OnConnectionLost on remote connect

Post by Mahmood_M » Mon 19 Oct 2015 15:05

Any Help !?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: OnConnectionLost on remote connect

Post by ViktorV » Tue 20 Oct 2015 08:28

The AfterDisconnect event occurs only when you explicitly disconnect from MySQL server, for example, by calling the TUniConnection.Disconnect method.
The OnConnectionLost event occurs not at the moment of disconnection, but in case when after connection breaks you are trying to access the server. Since you don't try to access the server after disconnection from the Internet, the OnConnectionLost event doesn't occur. The simplest way to check if the connection is lost is to send any command to the server via UniDAC, e.g., TUniConnection.Ping. If on execution of the TUniConnection.Ping method the server is unavailable, the OnConnectionLost event occurs.

Post Reply