Connection error trapping/handling code
You may wish to try the following connection error trapping/handling code. It works with a web (ASP "classic" vbscript) page and Oracle (but can easily be adapted to MSSQL by changing the provider string to SQLOLEDB, etc.)
' Partial MSSQL conn string syntax
e.g.; "Provider=SQLOLEDB; Data Source=svrSource; Initial Catalog=myDBName;"
<%
'************************************************* *******************************************
' Global Routines
'************************************************* *******************************************
Sub ConnectDB(oConn_Local)
On Error Resume Next
'Establish Connection to Oracle database.
Set oConn_Local = Server.CreateObject("ADODB.Connection")
oConn_Local.Open "Provider=MSDAORA;Password=myPWD;User ID=myUID;Data Source=myDS;Persist Security Info=True;"
' If connection error occurs, send user to "Under Construction" page
'
If Err.Number <> 0 Then
' Send mail to admin.
Dim objCDO
Set objCDO = Server.CreateObject("CDONTS.NewMail")
objCDO.TO = "test@acme.com"
'objCDO.CC = "test@acme.com"
objCDO.FROM = "server@acme.com"
objCDO.SUBJECT = "Possible connection problem with myApp - SOURCE: myServer"
objCDO.BODY = "SOURCE: myServer. Possible db/network connection problem with the myApp. Please check and repair if necessary."
objCDO.MailFormat = 1 ' CdoMailFormatText
objCDO.BodyFormat = 1 ' CdoBodyFormatText
objCDO.Send
Set objCDO = Nothing
Response.Redirect("http://www.someothersite/under_construction.htm")
End If
On Error GoTo 0
End Sub
Sub DisconnectDB(oConn_Local)
'Close and Destroy connection object.
If IsObject(oConn_Local) Then
If oConn_Local.State = adStateOpen Then
oConn_Local.Close
End If
Set oConn_Local = Nothing
End If
End Sub
%>