<% ' global variables myStatusOK = True ' build status message -- fights against page not being processed and just returning to browser myStatusMessage = "" myStatusMessage = "Status " myStatusMessage = myStatusMessage + "is " myStatusMessage = myStatusMessage + "OK" %> <% ' ' testDatabaseConnection - function to test database connection ' Function testDatabaseConnection (myConnectString, myUserName, myPassword) ' don't let errors screw everything up On Error Resume Next ' create connection object Set myTestConnection = Server.CreateObject("ADODB.Connection") ' open the connection myTestConnection.Open myConnectString, myUserName, myPassword ' test for errors in connection object If myTestConnection.Errors.Count > 0 Then ' count if there are any errors -- error number <> 0 myCountErrors = 0 For myCounter = 0 to myTestConnection.Errors.Count - 1 ' in general ignore warnings If (myTestConnection.Errors(myCounter).Number <> 0) Then myCountErrors = myCountErrors + 1 End If ' test for read only warning on Access databases If (InStr(1, myTestConnection.Errors(myCounter).Description, "is read-only", 1) > 0) Then myCountErrors = myCountErrors + 1 End If Next ' if we found any errors then describe them If myCountErrors <> 0 Then Response.Write("Errors have occurred:

") For myCounter = 0 to myTestConnection.Errors.Count - 1 ' in general ignore warnings If (myTestConnection.Errors(myCounter).Number <> 0) Then Response.Write("The " & myCounter & " error's error number is ") Response.Write(myTestConnection.Errors(myCounter).Number & ".
") Response.Write("The description for this error is
" & myTestConnection.Errors(myCounter).Description & ".

") End If ' test for read only warning on Access databases If (InStr(1, myTestConnection.Errors(myCounter).Description, "is read-only", 1) > 0) Then Response.Write("The " & myCounter & " error's error number is ") Response.Write(myTestConnection.Errors(myCounter).Number & ".
") Response.Write("The description for this error is
" & myTestConnection.Errors(myCounter).Description & ".

") End If Next myStatusOK = False Else ' let us know that a connection was established Response.Write("Connection successfully established.") End If Else ' let us know that a connection was established Response.Write("Connection successfully established.") End If ' reset objects Set myTestRecordset = Nothing Set myTestConnection = Nothing End Function %>

Test database

<% testDatabaseConnection "Test DSN", "Test Login", "Test Password" %>


<% ' write status statement If (myStatusOK = True) Then Response.Write(myStatusMessage) Else Response.Write("Status: errors on page") End If %>