Page 1 of 1

Test Server reachable BEFORE connect

Posted: 25.04.2017, 07:50
by af0815
Is it possible to test, if a server is reachable before the ZConnection is activated.

I looked inside the ping and pingserver, but both use FConnection, but FConnection is not created at this time. I want to use this to decide to use a buffed Dataset or to connect to a server. One goal is, the must not wait for an timeout. A ping on OS is possible, but i see only if the Server is up, not if a service is up and reachable.

I have searched around (in this forum too), but i found only entires the worked on a open Connection like reconnect and lost connection, not at 'befor connection' time.

Any hint to handle this ?

Andreas

Edit: Win10_64/Lazarus_32/ZeosTrunk/ado/MsSql

Re: Test Server reachable BEFORE connect

Posted: 26.04.2017, 22:46
by marsupilami
Hello Andreas,

Zeos doesn't provide anything to solve that problem. Mainly because Zeos is agnostic to networks and protocols and only uses client libraries. It doesn't know wether the database is working by TCP/IP, XNET air mail or smoke signals. ;) And client libraries usually only provide methods for connecting to the server.

Sayin you don't want to wait for a timeout isn't realistic - if you don't wait for a short time you don't give the other host a possibility to answer. So you always will have to live with a short timeout. What you could do is - you could try to create a tcp connection if you know the host name / ip address and port numer. Try to connect to it with a very small timeout - say 1 to 5 seconds and see wether you get a tcp connection. See if that works and if it works disconnect and do the real connection procedure.

Since your signature says, you are on MS SQL, this also might be something for you: http://stackoverflow.com/questions/4308 ... er#4308425

With best regards,

Jan

Re: Test Server reachable BEFORE connect

Posted: 27.04.2017, 15:02
by af0815
Ok, thanks Jan,

i ask this, because i found in ZAbstractconnection

this functions
function Ping: Boolean; virtual;
function PingServer: Boolean; virtual;
This was the reason for my question. I can use a ping for tests the server too, normally if the ping is ok, the DB is also reachable. Thx for the link, but i didnt want to deal with the connection-timeout. Normally its ok, but at startup without a (ping)check, the app look like hanging.

Andreas

Re: Test Server reachable BEFORE connect

Posted: 27.04.2017, 22:55
by marsupilami
Hello Andreas,

the ping method usually just uses the functionality of the database client library to ping the server as part ot its protocol. Firebird can do that as far as I know. I am not sure about MSSQL with ADO.

With best regards,

Jan