Error on data reading from the connection

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
FabioG
Posts: 1
Joined: Tue 11 May 2010 07:11

Error on data reading from the connection

Post by FabioG » Tue 06 Aug 2013 08:42

Hi all, I'm working with UniDac 5.0.1 and PostgreSQL version 9.1 server.
I just tried to lock with a select for update query some records (QUERY1).
Then I tried to do the same with a second connection (QUERY2) and instead of receiving a lock error I receive this exception:

Error on data reading from the connection

After the exception the UniConnection object is disconnected.
Is it normal?

Even if I close the second application with QUERY2, the postgres connection and the pending query stay resident on the postgres server until the first (QUERY1) app unlocks the records.

Is it possible to receive a different error on QUERY2 and possibly cancel this query if QUERY1 is locking same records?

Thank you.

DemetrionQ
Devart Team
Posts: 271
Joined: Wed 23 Jan 2013 11:21

Re: Error on data reading from the connection

Post by DemetrionQ » Tue 06 Aug 2013 15:03

Hello.

The "Error on data reading from the connection" error means that an error occurred on reading data from the socket, e.g., server connection break. In this case, connection closing will be a kind of standard behaviour.

If a record is already locked, when executing a query like

Code: Select all

SELECT * FROM table1 WHERE id = 1 FOR UPDATE;
client will be waiting for record unlock. If the connection breaks for some reason while waiting, you will get the "Error on data reading from the connection: ..." error.
In order for client not to wait for record unlock, but to get the "could not obtain lock on row ..." error immediately, a NOWAIT sql instruction should be added to the SELECT FOR UPDATE query, e.g.:

Code: Select all

SELECT * FROM table1 WHERE id = 1 FOR UPDATE NOWAIT;
If you work with an open dataset, it will be more convenient for you to lock a record using the TUniQuery.Lock method, which executes a similar SQL query (SELECT ... FOR UPDATE NOWAIT) for a current record. The detailed information about the TUniQuery.Lock method can be found at http://www.devart.com/unidac/docs/devar ... lock().htm

Post Reply