Click to See Complete Forum and Search --> : How to deal with SQL connection error in ASP code


kwilliams
02-15-2010, 09:06 AM
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 String
strConn = "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.

jonmaster
02-15-2010, 05:54 PM
you may use

On Error Resume Next for error handling.

what is the error you are getting,

kwilliams
02-16-2010, 02:11 PM
Thanks jonmaster,

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 0
If 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.