TZConnection (ZEOS) Timeout ? lazarus / 16-Databases ---------------------------------------------------------------------- caused · 2011-06-02 12:28 Hi, is there a simple way to add Timeout functionality to TZConnection. IE. when connecting to an non existing server the default timeout is around 20-30 seconds. ~caused ---------------------------------------------------------------------- JD · 2011-06-02 13:23 Use a timer (Lazarus has IdleTimer & Timer components). a) Enable it in ZConnection1.BeforeConnect OR directly in a loop before calling ZConnection1.Connect b) As long as 20 - 30 secs have not elapsed, try to connect c) If connection is still not possible after 20 - 30 secs, abort & inform the user Note that you have to catch the exception raised in (b) above with a helpful message saying for example "Trying to connect to the database ...." ---------------------------------------------------------------------- caused · 2011-06-02 13:34 Hey JD, the problem is, that the default timeout is around 20 -30 seconds, which is MUCH too long. So the timer method would probably not work ;/ ~caused ---------------------------------------------------------------------- JD · 2011-06-02 14:50 Why don't you ping the server first before attemping to connect to it? You are not the only one with this problem. It has already been brought up on the Zeos forum ZConnection hangs for nonexistent server http://zeos.firmos.at/viewtopic.php?t=2454&highlight=timeout Request TimeOut Value Property for ZConnection http://zeos.firmos.at/viewtopic.php?t=1970&highlight=timeout I always wrap my code in try....finally & try....except constructs to avoid this problem & it works so far. For example Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {---------- --------------------------------------------------------------------  Function: Connect----------------------------------------------------- --------------------------}function TfrmMainform.Connect(): Boolean;begin  // Connect to the database  with Datamodule1.ZConnection do  begin    try      Connect;      IsConnected := True;    except      On E: Exception do      begin      IsConnected := False;        ShowMessage('Cannot connect to the database at the moment. Please try again later.');      end;    end;  end;  Result := IsConnected;end; With the code above, I get an exception in about 5 - 7 seconds if a connection is not possible. I can then proceed based on what the Connect function returns. Remember that the speed of the network also comes into play here. The faster the network, the quicker the response. It is very basic but it works for me. But your mileage may vary... JD ---------------------------------------------------------------------- nicke85 · 2011-06-04 11:14 this is part of code from one my aplication before try-except statement Code: [Select]with dbz.ZConnection1 do                 Begin                 Database:=Edit2.Text;                 HostName:=Edit1.Text;                 Password:=Edit4.Text;                 User:=Edit3.Text;                 Properties.Add('codepage=win1250');                 Properties.Add('client_encoding=win1250');                 Properties.Add('timeout=5'); it work on linux,win7 and winxp