Member Login

Username
Password
Forget Password
New Sign Up
Search Forum

Buy Support
Incidents

If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:

Click Here
If you can't login and post questions or you are having trouble viewing forum posts:
Click Here
Callback
Support

If you live in USA, UK, Canada, Australia or New Zealand, you can leave us details on your question and request us to call you back and discuss them with you personally  (charges apply).

Click Here
 
Buy Support
Incidents
If you can't find your answer in the FREE PUBLIC QDeveloper Forum, require URGENT Priority Support, or you need to send us private or confidential information:
Click Here

Forum : How do I trap errors coming back from QODBC in VB/ADO/ASP code?Search Forum

Forum Home > QODBC - ODBC Driver for QuickBooks > QODBC SQL Support Forum

 New Topic 
 
 Post Reply 
[1]  
 How do I trap errors coming back from QODBC in VB/ADO/ASP code? 
 Author   Message 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-04-22 11:00:47

Error trapping is a function of your programming interface, not QODBC. When debugging OLE DB Provider-specific ADO problems, you can dump the contents of the Errors collection to the immediate window with the following code:

For Each objError in objConn.Errors
            Debug.Print objError.Description
Next objError

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-04-22 23:43:33

The question now is how to we "trap" QODBC Insert errors? Well, after any QODBC insert, we will want to put the following lines:

If Err.number <> 0 then
  TrapError Err.description
End If

You will want to put this after all ADO calls that communicate directly with QODBC. This includes ConnectionObject.Open, ConnectionObject.Execute, and RecordsetObject.Open. Now, you may be wondering where the sub TrapError is defined: we're about to do that. Create a file called ErrorHandler.asp and put it in your /include or /scripts directory. In ErrorHandler.asp, we will have the following subs:

TrapError
ProcessErrors

Let's look at the code for ErrorHandler.asp:

<%
Dim strErrorMessage
Dim bolErrors

'Initialize variables
strErrorMessage = "" 'The error messages for tech. support
bolErrors = False 'Have we found any errors yet?

'Now our two subs
sub TrapError(strError)
  bolErrors = True 'We've found an error!

  strErrorMessage = strErrorMessage & strError & ", "
end sub

'If there are any errors, this function will show the error
sub ProcessErrors()
  if bolErrors then
    'Show the Error

    Response.Write "There has been a QODBC error. " & _
                    "At " & Now & " the following errors occurred on " & _
      "the page " & Request.ServerVariables("SCRIPT_NAME") & _
      ": " & _
                    chr(10) & chr(10) & strErrorMessage
  end if
end sub 

%>

That's all there is to it! Now, at the top of all your pages that you want to use the error handling routines, you'll need to include ErrorHandler.asp like so:

<!--#include virtual="/include/ErrorHandler.asp"-->

 

  Top 
  jeff 
  
 Group: Members 
 Posts: 76 
 Joined: 2006-06-03 
 Profile
 Posted : 2006-06-27 09:12:27

I tried the above code to catch error codes, however the I get the following result when running an insert on a customer

-2147467259Unspecified error  

How can I get the error message that comes from the QBXMLResponse instead of the above useless error message?

Here is the VBScript code:

set conn=Server.CreateObject("ADODB.Connection")

conn.ConnectionString= "DSN=QuickBooks Data" conn.Open() set command = Server.CreateObject("ADODB.Command") command.ActiveConnection = conn

'code below inserts a duplicate customer

command.CommandText = "insert into Customer (name) values ('jeff')"

on error resume next

 command.Execute() if err.number <> 0 then

 For Each objError in conn.Errors

 Response.Write(err.number)

 Response.Write( objError.Description)

Next

end if

on error goto 0

 if conn.State = 1 then

 conn.close

end if

 set conn = nothing

 

  Top 
  jeff 
  
 Group: Members 
 Posts: 76 
 Joined: 2006-06-03 
 Profile
 Posted : 2006-06-28 11:21:55

Just wondering in anyone had a response related to how to retrieve QBXML  Response error code and error message using QODBC? This is important, if it can't be done please say so.

 

  Top 
  Tom 
  6c3c1_sdk-qodbc.gif
 Group: Administrator 
 Posts: 5510 
 Joined: 2006-02-17 
 Profile
 Posted : 2006-06-28 11:56:32
Error trapping is a function of your programming interface, not QODBC. Please consult the programming reference for your development platform revision for further information. 

  Top 
  jeff 
  
 Group: Members 
 Posts: 76 
 Joined: 2006-06-03 
 Profile
 Posted : 2006-06-30 04:05:49

Here is the msdn documentation just for every bodys knowledge.

http://msdn2.microsoft.com/en-us/library/ms189583.aspx

ADO uses an errors object and errors collection to return standard error information such as SQLSTATE, native error number, and the error message string. These are the same as their ODBC counterparts. ADO does not support any provider-specific error interfaces; Database Engine-specific error information, such as the severity or state, is not available to ADO applications.

I believe that this means that there is no way for me to retrieve the QBXML Response error code and message via asp and ADO.

 

  Top 
  jeff 
  
 Group: Members 
 Posts: 76 
 Joined: 2006-06-03 
 Profile
 Posted : 2006-07-28 05:17:17

Disregard my last post here. For those of you using javascript to write ADO when catching errors use:

try{

//some ADO code here

}

catch(e){

Response.Write(e.description);
}

Note the use of the lower case "d" in "description". This solved the problem for me. I figured this out by accident and suddenly the error message come back exactly like the QODBC tester interface.

 

  Top 
 New Topic 
 
 Post Reply 
[1]  

Jump to