Recent

Author Topic: Zeos - TZquery, catch lost connection ?  (Read 4732 times)

fjabouley

  • Full Member
  • ***
  • Posts: 128
Zeos - TZquery, catch lost connection ?
« on: October 22, 2020, 08:33:21 am »

Hello !


I have many opened Tzquery components working with a TZconnection, and if the connection is lost, I would like to connect back to the database, without showing "error writing to DB....".


Do you know if there is a way to globally catch a database disconnection with zeos ?


Have I to check Tzconnection.pingserver each time I do a request with a TzQuery?


Many thanks to you all !

EgonHugeist

  • Jr. Member
  • **
  • Posts: 78
Re: Zeos - TZquery, catch lost connection ?
« Reply #1 on: October 22, 2020, 04:30:48 pm »
The upcomming Zeos Version 8 as a connection Event "OnLost".

If this event is triggered, all objects are closed than. IMO Only choice is to reopen all datasets if you can reconnect. Pinging the servers would only help to find out if you CAN reconnect. Connection loss can happen everythime, while reading, writting, commit etc. So continue work, without refreshing everything (except loaded+cached datasets) won't be possible.

fjabouley

  • Full Member
  • ***
  • Posts: 128
Re: Zeos - TZquery, catch lost connection ?
« Reply #2 on: October 23, 2020, 08:01:11 am »
Thanks for your reply.
Is there at least a way to catch the writing error when a connection is dropped with visual components ? and then close all datasets, reconnect and re-open them ?
Regards

EgonHugeist

  • Jr. Member
  • **
  • Posts: 78
Re: Zeos - TZquery, catch lost connection ?
« Reply #3 on: October 23, 2020, 08:40:24 am »
A writing error can't be explicitly determined. According the Components:
Yes, it is but you don't need todo anything by hand. IIRC if a "connection loss" is triggered, all datasets, sequence-componenents, listeners, transaction-components, streams getting closed immediately. Finally you'll get a Conenction lost exception. If the Event is not assigned.
I've to correct myself: Pinging the server won't be possible anymore because the handles are flushed. But you can use the pings as something like "keep alive" packages to prevent disconnect timeouts.

https://sourceforge.net/p/zeoslib/code-0/HEAD/tree/ Click download snapshot.
« Last Edit: October 23, 2020, 08:42:34 am by EgonHugeist »

fjabouley

  • Full Member
  • ***
  • Posts: 128
Re: Zeos - TZquery, catch lost connection ?
« Reply #4 on: October 27, 2020, 01:31:19 pm »
Thanks.
I installed svn version, and everything seems to work well. I didn't try to use Onlost, I will do it later.
I have this error that appears while I try to use CreateBlobStream(FieldByName(...), bmread)
It worked well before. Is this a bug ? How could I get the stream?
Regards !



« Last Edit: October 27, 2020, 02:17:57 pm by fjabouley »

EgonHugeist

  • Jr. Member
  • **
  • Posts: 78
Re: Zeos - TZquery, catch lost connection ?
« Reply #5 on: October 27, 2020, 06:19:30 pm »
Propose to change the Forum. This is a second question except it's related to the topic. Is it? This forum is made for FPC-SQLDB not for Zeos DBO. Ask in the Zeos forum: https://zeoslib.sourceforge.io/index.php. And no i would not start from the premisse it's a bug (except its topic related). The exception says: You have a open LOB-Stream and you are closing the DataSet/Resultset. You can't access the stream after the dataset/resultset is closed. If you want that, make your own copy.
« Last Edit: October 27, 2020, 07:58:02 pm by EgonHugeist »

fjabouley

  • Full Member
  • ***
  • Posts: 128
Re: Zeos - TZquery, catch lost connection ?
« Reply #6 on: October 28, 2020, 08:09:40 am »
Thank you for your answer.
You're right, I think I might post this in zeos forum. Not sure it is a bug indeed, but this happened when I upgraded zeos. The issue was not present before.
(I try to assign a memorystream (Memorystream.loadfromstream(createblobstream(.... But I don't know how to close it because the stream is the result of the Createblobstream function...)
Best regards.


fjabouley

  • Full Member
  • ***
  • Posts: 128
Re: Zeos - TZquery, catch lost connection ?
« Reply #7 on: November 21, 2020, 12:54:30 pm »
Sorry EgonHugeist, my bad
 
Code: Pascal  [Select][+][-]
  1.  
  2. jmst := tmemorystream.Create;
  3.  
  4.  
  5. // jmst.loadFromStream(CreateBlobStream(FieldByName('DATAS'), bmread));
  6.  
  7.  
  8. (FieldByName('DATAS') as TBlobField).SaveToStream(jmst);
  9. jmst.Position:=0;
  10. usrimg := TPortableNetworkGraphic.Create;
  11. usrimg.LoadFromStream(jmst);  
  12. jmst.free;
  13. usrimg.free;
  14.  
I changed it using Field as Blobfield.savetostream, and now it works.
I won't use createblobstream anymore, but is ther a way to free it ??


I'll try the onLost connection soon, thanks for everything !
Best regards


fjabouley

  • Full Member
  • ***
  • Posts: 128
Re: Zeos - TZquery, catch lost connection ?
« Reply #8 on: November 22, 2020, 09:34:17 am »
So I tried the onLost, just showing a message dialog when the connection is dropped, but it didn't show anything and I don't know how it can be triggered...
Actually I tried to reboot firebird server while running the application, with some opened datasets, but the OnLost function is never executed. Am I doing something wrong ? Perhaps it doesn't work this way... When I currently try to update the dataset (while database server is rebooted), it raises a SQL error, that was formerly shown in the previous zeos versions.
Could you please tell me how to handle this function correctly ? 
Best regards.

 

TinyPortal © 2005-2018