• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 242
  • Last Modified:

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_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                        
                  SendTextMail "support@xyz.com.au","webrs@xyz.com.au",  _
                                          "","","Error(s) occured on the site",sEmailMsg
                  Set cnDB = Nothing
            end if
      End Sub
  • 4
1 Solution
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
try this:

Dim conn
set conn = CreateObject("ADODB.Connection")
conn.open MM_connDBA_STRING

CheckForDbErrors (conn)
Why a B?? I pointed out the error and showed how to fix it, therefore completely answering the question
philwill4uAuthor Commented:
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.

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now