Set timeout for the database connect statement.

Sundreamz

New Member
Hi Friends,


I am trying to connect to a database named "archive". This database is available in some hosts and not available in others.
The connect statement below tries to connect to the "archive" database and returns the message as "connected" if the database connetion happens successfully.
If the the connect statement is not able to connect to the database for some hosts then it hangs for a long time then terminates with message ** Could not connect to server for database <DATABASE>, errno <ERRNO>.
It does not show it the database is connected or not with this scenario.

Now My question: Is it possible to set a timeout CONNECT Statement.
i.e. if the connect statement runs for a specified period of time then stop connecting to the dabase. I don want the system to hand for a long time bcos of connect statement.


def var mDBConnectString as char.
mDBConnectString = "archive" + " -S " + "ta1-arch1" + " -H " + "hostname".
message "connecting" view-as alert-box.
CONNECT VALUE(mDBConnectString).
IF CONNECTED ('archive') then message "connected" view-as alert-box.
ELSE message "not connected" view-as alert-box.

Thanks In Advance,
Rgds,
Sandeep
 
I haven't tested it, but the following might work.

Code:
CONNECT VALUE(mDBConnectString) NO-ERROR.

You then could use the ERROR-STATUS system handle to check why it couldn't connect. I don't know if it will solve your problem of the long wait, but it's worth a try...
 
Thanks for the update.

I have tried using error status. But it does not solve my problem of "CONNECT" statement taking longer time than expected.

Rgds,
Sandeep
 
This might help : in stead of directly connecting to the database, first make a socket connection to check the availability.


Code:
DEFINE VARIABLE sk AS HANDLE NO-UNDO.
create socket sk.
sk:connect(" -S " + "ta1-arch1" + " -H " + "hostname") no-error.
if not sk:connected() then ...


This connect statement will time out MUCH faster than a database connect statement.
 
ThanQ Kris, that works to perfect for my cause.
I don have to connect to the database if the socket connection fails. thats gr8 :)
 
Back
Top