Recent

Author Topic: How to test if a TConnection is active before trying to read data.  (Read 3756 times)

vfclists

  • Hero Member
  • *****
  • Posts: 825
    • HowTos Considered Harmful?
Is there a way of testing when a TZConnection is active when the network is down?

The TZConnection.Connected property is true even when the network connection is down, and it doesn't seem to change when an attempt to connect to the database fails.

Isn't there a way of monitoring the TZConnection rather than trying to open a table and realizing that the connection is down?

Is there also a way of trapping the exception when you try to open the table when there is no connection? I try testing for E:EZSQLException but it doesn't seem to catch everything.
« Last Edit: July 12, 2010, 01:24:06 pm by vfclists »
Windows - Lazarus 1.0.8/FPC 2.6.0
Linux - Lazarus 1.4.4 /FPC 2.6.4

Mujie

  • Jr. Member
  • **
  • Posts: 64
Re: How to test if a TConnection is active before trying to read data.
« Reply #1 on: July 25, 2010, 06:00:33 pm »
Why do not you use simple logic "if else" condition ?

Code: [Select]
if succeed then
begin
  //your code
else
begin
  //terminated
end;

fredycc

  • Sr. Member
  • ****
  • Posts: 265
Re: How to test if a TConnection is active before trying to read data.
« Reply #2 on: July 26, 2010, 03:32:04 am »
Depends of your database engine you can use for example like Mujie suggest before Execute or open datasets:

Quote
  ZConnection1.Ping
              or
  ZConnection1.PingServer