Using the TSQLConnection component in Delphi XE2 to connect to a DataSnap server.
My problem is that I would like to abort the connection attempt if we're unable to connect after 3 seconds, however setting the ConnectTimeout property of the driver doesn't seem to have any impact (it still waits around 20 seconds before giving up).
I'm running this inside a thread and so I could post a message to the thread (how whether the thread message queue is serviced depends, I suppose, on how this blocking call was created). Even if my thread message handler ran, I'm unsure how I'd then interrupt the blocking the call to set the TSQLConnection.Connected property (which is set within the Execute method of the thread).
I'd prefer not call TerminateThread as this seems overkill and would leave (if I understand correctly) the memory allocated to the thread's stack. Any ideas on how to interrupt this connection process, or access the underlying Indy components and explicitly set the connection timeout there would be appreciated.
Thanks!
fConnection := TSQLConnection.Create(nil);
with fConnection do
begin
DriverName := 'DataSnap';
Params.Values['CommunicationProtocol'] := 'tcp/ip';
Params.Values['DatasnapContext'] := 'datasnap/';
Params.Values['HostName'] := '127.0.0.1';
Params.Values['Port'] := '211';
Params.Values['ConnectTimeout'] := '3000';
KeepConnection := true;
LoginPrompt := true;
end;
// Where it blocks for up to 20 seconds (if host unavailable)
fConnection.Connected := True;
I think about this and if ConnectTimeout not work then you can solve this in another way
first before connect try to ping dest host by e.g Indy component (if this is not the localhost ;-)) or better try telnet service port (also by Indy) - i suppose that this is the simplest think what you can do now without killing the thread
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With