Detecting connection loss? Doesn't work

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
zd
Posts: 78
Joined: Sun 01 Jul 2007 13:16

Detecting connection loss? Doesn't work

Post by zd » Tue 16 Sep 2008 16:38

Hi!

My client app is running in a stable network. It's connected to the server either through LAN or the Internet - using TCP based connection.

There could be two causes of connection loss:
1, The user hybernates his/her computer (then relaunches it)
2, The user forces a disconnection from the network through windows (by disabling WLAN, unplugging network cable etc.)

In both cases, I'd like to detect the connection loss in my app, and prompt the user to reconnect with a dialog.

The problem:
As I understand, in order to use the OnConnectionLost event, you have to set LocalFailover to true, include MemData in uses list and set Transactions to ReadOnlyReadCommitted.

But all my transactions are readcommitted (not readonlyreadcommitted) and I can't change that!

This way, even if I set LocalFailover to true, the OnConnectionLost event doesn't occur!

How does IBDAC keep the connection to the server? Does it ping the server automatically? Is there a variable to specify pinging interval?

Is there a way to promptly detect connection loss when the computer is disconnected from the network?

Right now no event is generated, but when a query is launched (after being disconnected), there are a bunch of "Error writing data to connection" dialogs and "Unknown isc error 0" dialogs are popping up while Access Violations keep happening!

Thanks:
Zd

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 19 Sep 2008 08:13

The OnConnectionLost event is raised only if reconnect is available. To make it available use separate transactions for reading and updating data. Use the UpdateTransaction property of TIBCQuery to set an update transaction for executing SQLInsert, SQLUpdate and SQLDelete statement when you edit the dataset.

The read transaction should have the ReadOnlyReadCommited isolation level. The update transaction can be ReadCommited. This transaction is started when a SQL is executed and commited after the execute. So it is active only short time, and probably will be inactive when the connection is lost. So the reconnect will be available.

IBDAC does not ping the server. It detects the connection loss when it executes a query and gets an error.

You can detect the connection loss by yourself when trying to execute some query.

zd
Posts: 78
Joined: Sun 01 Jul 2007 13:16

Post by zd » Fri 19 Sep 2008 11:49

Thanks for the answer Plash.

The problem is that my program is written to use the DefaultTransaction for both reading/updating already, and I don't really fancy rewriting it.

Is there a way to directly check whether you're connected to the database or not, BEFORE executing a query?

This way I could insert the check in a function before each DB statement and offer to reconnect if disconnection is detected...

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Mon 22 Sep 2008 06:43

You can execute some test query or read data from the DatabaseInfo property of TIBCConection:

Code: Select all

  try
    IBCConnection.DatabaseInfo.BaseLevel;
  except
    ShowMessage('connection lost');
  end;

Post Reply