philwill4u
asked on
Error Handling a ADODB connection
I have a piece of code and an include file that manages errors - CheckForDbErrors. I've artificially created an error in the code but can't seem to get it to call the error routine. Here's the code: Can you help? I think it may have something to do with the line 'CheckForDbErrors (rsReceipt)'
**** the main code ********
<%
On error resume next
Dim rsReceipt
Dim rsReceipt_numRows
Set rsReceipt = Server.CreateObject("ADODB .Recordset ")
rsReceipt.ActiveConnection = MM_connDBA_STRING
rsReceipt.Source = "SELECT * FROM CustOrderReceipt WHERE OrID = " + Replace(rsReceipt__MMColPa ram, "'", "''") + ""
rsReceipt.CursorType = 0
rsReceipt.CursorLocation = 2
rsReceipt.LockType = 1
rsReceipt.Open()
rsReceipt_numRows = 0
CheckForDbErrors (rsReceipt)
%>
*** CheckForDBErrors include file ***
<%
Sub CheckForDbErrors(objConn)
'Used to check database calls
'Errors means the count will be more than 0
If objConn.error.count > 0 then
Dim cnDB,sSQL
Dim sEmailMsg
Dim vbCrLf
vbCrLf = Chr(13) + Chr(10)
Set cnDB = Server.CreateObject("ADODB .Connectio n")
cnDB.Open MM_connDBA_STRING
response.write("there's been and error")
sEmailMsg = "An Error occured at the site, Please find below " & _
"the error details:-" & vbCrLf
For Each objError in objConn.Errors
sSQL = "INSERT INTO [ErrorLog] (ErrorNo,ErrorDescp,ErrorS ource) VALUES ('" & _
Err.number & "','" & Err.Description & "','" & Err.Source & "')"
cnDB.Execute sSQL
sEmailMsg = sEmailMsg & "Error No :" & Err.number & vbCrLf
sEmailMsg = sEmailMsg & "Error Desp :" & Err.Description & vbCrLf
sEmailMsg = sEmailMsg & "Error Source:" & Err.Source & vbCrLf
sEmailMsg = sEmailMsg & "Error Time :" & Now() & vbCrLf
Next
SendTextMail "support@xyz.com.au","webr s@xyz.com. au", _
"","","Error(s) occured on the site",sEmailMsg
cnDB.Close
Set cnDB = Nothing
Err.Clear
end if
End Sub
%>
**** the main code ********
<%
On error resume next
Dim rsReceipt
Dim rsReceipt_numRows
Set rsReceipt = Server.CreateObject("ADODB
rsReceipt.ActiveConnection
rsReceipt.Source = "SELECT * FROM CustOrderReceipt WHERE OrID = " + Replace(rsReceipt__MMColPa
rsReceipt.CursorType = 0
rsReceipt.CursorLocation = 2
rsReceipt.LockType = 1
rsReceipt.Open()
rsReceipt_numRows = 0
CheckForDbErrors (rsReceipt)
%>
*** CheckForDBErrors include file ***
<%
Sub CheckForDbErrors(objConn)
'Used to check database calls
'Errors means the count will be more than 0
If objConn.error.count > 0 then
Dim cnDB,sSQL
Dim sEmailMsg
Dim vbCrLf
vbCrLf = Chr(13) + Chr(10)
Set cnDB = Server.CreateObject("ADODB
cnDB.Open MM_connDBA_STRING
response.write("there's been and error")
sEmailMsg = "An Error occured at the site, Please find below " & _
"the error details:-" & vbCrLf
For Each objError in objConn.Errors
sSQL = "INSERT INTO [ErrorLog] (ErrorNo,ErrorDescp,ErrorS
Err.number & "','" & Err.Description & "','" & Err.Source & "')"
cnDB.Execute sSQL
sEmailMsg = sEmailMsg & "Error No :" & Err.number & vbCrLf
sEmailMsg = sEmailMsg & "Error Desp :" & Err.Description & vbCrLf
sEmailMsg = sEmailMsg & "Error Source:" & Err.Source & vbCrLf
sEmailMsg = sEmailMsg & "Error Time :" & Now() & vbCrLf
Next
SendTextMail "support@xyz.com.au","webr
"","","Error(s) occured on the site",sEmailMsg
cnDB.Close
Set cnDB = Nothing
Err.Clear
end if
End Sub
%>
rsReceipt is a recordset, and your error routine expects a connection object
you need to call CheckForDbErrors and pass it a connection object instead of a recordset
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Why a B?? I pointed out the error and showed how to fix it, therefore completely answering the question
ASKER
You answered the question but I thought excellent was for going beyond what's requested. Good is for simply answering the question. Excellent would be for say, showing an error routine for managing recordsets with no explicit connection defined.