kwilliams Posted February 15, 2010 Share Posted February 15, 2010 We have an application that pulls data from several servers, and one of the external servers that we don't have control of went down recently. When our code attempted to open the connection string to that server, it pulled our entire application down.So I need to know how to check that a connection is working first *before* attempting to open it, so that it won't bring everything else down with it. here is what the connection string looks like: Dim strConn As StringstrConn = "Provider=SQLOLEDB; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; User ID=USERID; Password=PASSWORD" And here is the line of code that had the error: objConn = Server.CreateObject("ADODB.Connection") objConn.Open (strConn) '<<<----- ERROR OCCURRED HERE!!! And and all help is appreciated. Link to comment Share on other sites More sharing options...
justsomeguy Posted February 16, 2010 Share Posted February 16, 2010 So I need to know how to check that a connection is working first *before* attempting to open itOpening a connection is what you do to test it. You could open a different connection, like a socket connection, and see if it connects to the hostname. But the ADODB connection provider does some things automatically (like figures out which port to use, etc), so you would need to add that in yourself to the socket code if you want to go that route.Another solution would be to detect when the error happens and deal with it instead of letting it be a fatal error. Look into exception handling for how to handle errors when they happen. Link to comment Share on other sites More sharing options...
kwilliams Posted February 16, 2010 Author Share Posted February 16, 2010 Opening a connection is what you do to test it. You could open a different connection, like a socket connection, and see if it connects to the hostname. But the ADODB connection provider does some things automatically (like figures out which port to use, etc), so you would need to add that in yourself to the socket code if you want to go that route.Another solution would be to detect when the error happens and deal with it instead of letting it be a fatal error. Look into exception handling for how to handle errors when they happen.Thanks justsomeguy,I received a similar response somewhere else with this example:...objConn = Server.CreateObject("ADODB.Connection")objConn.ConnectionTimeout = 10 On Error Resume Next objConn.Open (strConn)On Error GoTo 0If objConn.State <> 1 Then ... unable to connect to that db ... ... so you get to figure out how to handle that ... ... note that objConn is now useless, so don't attempt to use it ... Else ... should be okay End If...I've added that code without any problems, so we'll see if it works on the next error. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.