Test Server reachable BEFORE connect

The forum for ZeosLib 7.2 Report problems. Ask for help, post proposals for the new version and Zeoslib 7.2 features here. This is a forum that will be edited once the 7.2.x version goes into RC/stable!!

My personal intention for 7.2 is to speed up the internals as optimal a possible for all IDE's. Hope you can help?! Have fun with testing 7.2
Post Reply
af0815
Fresh Boarder
Fresh Boarder
Posts: 18
Joined: 24.03.2017, 12:49

Test Server reachable BEFORE connect

Post 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
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Test Server reachable BEFORE connect

Post 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
af0815
Fresh Boarder
Fresh Boarder
Posts: 18
Joined: 24.03.2017, 12:49

Re: Test Server reachable BEFORE connect

Post 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
marsupilami
Platinum Boarder
Platinum Boarder
Posts: 1918
Joined: 17.01.2011, 14:17

Re: Test Server reachable BEFORE connect

Post 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
Post Reply