I have a website developed using ASP and VBScript. I have 2 ASP files: services.asp and functions.asp. I have an On Error Resume Next statement in functions.asp. I put an error in my connection string to test the On Error Functionality but it does not behave as I expected. The error generates at the myConnection.Open ConnStr statement but the HandleADOError is never called. I put Response.Write statements in and those that appear before the open statement are printed but those after the Open statement within the OpenDatabase function do not. (I commented out the call to the HandleADOError function and replaced it with a Response.Write statement which is never written.) The function returns false so my "Error found" message is written. Can't figure out what I'm doing wrong. Any help would be greatly appreciated.
Services.asp calls functions defined in functions.asp. Services.asp has the following at the top of its page:
<!-- #include file="functions.asp" -->
<%
' Open connection to database
if NOT OpenDatabase() then
Response.Write "Error found"
'Response.Redirect "error.asp"
end if
%>
Functions.asp is defined as follows:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Option Explicit
Dim myMail, myConnection, rsCareType
On Error Resume Next
function OpenDatabase()
Dim ConnString
Set myConnection = Server.CreateObject("ADODB
.Connectio
n")
if err.number <> 0 then
OpenDatabase = false
else
myConnection.Errors.Clear(
)
'define the connection string, specify database driver
ConnString = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=myserver.com; " &_
"PORT=3306; DATABASE=dbname; UID=userid;PASSWORD=passwo
rd; OPTION=3"
myConnection.Open ConnString
if myConnection.Errors.Count > 0 then
Call HandleADOError()
OpenDatabase = false
else
OpenDatabase = true
end if
end if
end function
sub HandleADOError()
Dim objErr, errMsg
errMsg = ""
for each objErr in myConnection.Errors
errMsg = errMsg & "<p>"
errMsg = errMsg & "Description: "
errMsg = errMsg & objErr.Description & "<br />"
errMsg = errMsg & "Help context: "
errMsg = errMsg & objErr.HelpContext & "<br />"
errMsg = errMsg & "Help file: "
errMsg = errMsg & objErr.HelpFile & "<br />"
errMsg = errMsg & "Native error: "
errMsg = errMsg & objErr.NativeError & "<br />"
errMsg = errMsg & "Error number: "
errMsg = errMsg & objErr.Number & "<br />"
errMsg = errMsg & "Error source: "
errMsg = errMsg & objErr.Source & "<br />"
errMsg = errMsg & "SQL state: "
errMsg = errMsg & objErr.SQLState & "<br />"
errMsg = errMsg & "</p>"
next
Call SendMail("email@mydomain.o
rg", "email@mydomain.org", "", "ADO Error", errMsg)
end sub
Start Free Trial