Error Handling a ADODB connection

Posted on 2006-03-19
Last Modified: 2010-04-06
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 "","",  _
                                          "","","Error(s) occured on the site",sEmailMsg
                  Set cnDB = Nothing
            end if
      End Sub
Question by:philwill4u
    LVL 35

    Expert Comment

    rsReceipt is a recordset, and your error routine expects a connection object
    LVL 35

    Expert Comment

    you need to call CheckForDbErrors  and pass it a connection object instead of a recordset
    LVL 35

    Accepted Solution

    try this:

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

    CheckForDbErrors (conn)
    LVL 35

    Expert Comment

    Why a B?? I pointed out the error and showed how to fix it, therefore completely answering the question

    Author Comment

    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

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    When you work with shopping cart / ecommerce relates web sites, you need to pass the certain form post details to the payment gateway process page with required details for the products items you give to order. Also you may need to track the ordered…
    It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
    HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

    728 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now