Classic ASP ProfessionalFor advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
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:
Code:
Dim strConn As String
strConn = "Provider=SQLOLEDB; Data Source=SERVERNAME; Initial Catalog=DATABASENAME; User ID=USERID; Password=PASSWORD"
<%
...
objConn = Server.CreateObject("ADODB.Connection")
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
...
Fair warning: The attempt to open *could* take some time if you are trying to open across a network and the network is down. Because the driver will need to wait for the timeout on the network connection. You can control that by specifying a shorter time for the connectiontimeout:
Code:
Set conn = ...
conn.ConnectionTimeout = 10
On Error Resume Next
conn.Open ...
Just don't set the time too short so that even normal connection opens fail.
I've added the code without a problem, but I'm not sure how to check that what I've added works because that connection is now working. Do you have any suggestions on how I could test it?
Thanks for that information. I wouldn't be able to do the first, but I already have SQL Server Express installed on my machine, so the second option should work. Thanks again for your help!