Jump to content
kwilliams

How To Deal With Sql Connection Error In Asp Code

Recommended Posts

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.

Share this post


Link to post
Share on other sites
So I need to know how to check that a connection is working first *before* attempting to open it
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...