ADO connection when server is down takes too long before it fails

realdata used Ask the Experts™
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>Stopped at "&time)
      response.end      'write error message to user and stop execution
             end if            
            exit do
        end if
        set n=nothing      
End Sub 'checkConnection
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007
You have to set a connectiontimeout, that tell the connection how long to wait before aborting. 

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial