Link to home
Create AccountLog in
Avatar of philwill4u
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__MMColParam, "'", "''") + ""
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.Connection")
                  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,ErrorSource) 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","webrs@xyz.com.au",  _
                                          "","","Error(s) occured on the site",sEmailMsg
                  cnDB.Close
                  Set cnDB = Nothing
                  Err.Clear
            end if
             
      End Sub
%>
Avatar of YZlat
YZlat
Flag of United States of America image

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
Avatar of YZlat
YZlat
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Why a B?? I pointed out the error and showed how to fix it, therefore completely answering the question
Avatar of philwill4u
philwill4u

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.