realdata
asked on
ADO connection when server is down takes too long before it fails
I have written a sub in asp that checks for a connection to a database on sql server. If the connection state is 0 then it will try to reconnect three times before failing. When the server is up the connection is established instantly, but when the server is down it takes an average of 17 seconds to try to connect for the first time. The second and third times are always instantly. Is 17 seconds normal or is there something else I can do to speed this up in my code.
Here is my sub:
Sub checkConnection(objConn, strConn)
n = 0 'set loop counter to zero
on error resume next 'stop preset error message from showing
do while n < 4
if objConn.State = 0 then 'not connected
response.write("Try to Connect "&time&"<BR>")
objConn.Open strConn 'try to connect
n= n + 1 'increment loop counter
if n = 3 then 'tried three times without success
response.write("<font size = '5'>Could not connect to Database</font>")
response.write("<BR>Stoppe d at "&time)
response.end 'write error message to user and stop execution
end if
else
exit do
end if
loop
set n=nothing
End Sub 'checkConnection
Here is my sub:
Sub checkConnection(objConn, strConn)
n = 0 'set loop counter to zero
on error resume next 'stop preset error message from showing
do while n < 4
if objConn.State = 0 then 'not connected
response.write("Try to Connect "&time&"<BR>")
objConn.Open strConn 'try to connect
n= n + 1 'increment loop counter
if n = 3 then 'tried three times without success
response.write("<font size = '5'>Could not connect to Database</font>")
response.write("<BR>Stoppe
response.end 'write error message to user and stop execution
end if
else
exit do
end if
loop
set n=nothing
End Sub 'checkConnection
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.