Computers & ProgrammingADOBackend Development

ADO Capturing Errors

Troubleshooting errors within your ASP web application can be challenging sometimes. When working with ADO, the Error object can be used since it contains details about data access errors that have been generated during a single operation.

ADO will generate one Error object for each error. Each Error object contains details of the specific error. To access the errors, you must refer to a specific connection. Here is an example of how we can loop through the Errors Collection:

Syntax

objErr.property

Properties

PropertyDescription
DescriptionReturns an error description
HelpContextReturns the context ID of a topic in the Microsoft Windows help system
HelpFileReturns the full path of the help file in the Microsoft Windows help system
NativeErrorReturns an error code from the provider or the data source
NumberReturns a unique number that identifies the error
SourceReturns the name of the object or application that generated the error
SQLStateReturns a 5-character SQL error code

Example

<%
oConn.Execute sql
if err<>0 then
    for each objErr in oConn.Errors
      response.write("<table>")
      response.write("<tr><td>Description</td><td>")
      response.write(objErr.Description & "</td></tr>")
      response.write("<tr><td>Help context</td><td>")
      response.write(objErr.HelpContext & "</td></tr>")
      response.write("<tr><td>Help file</td><td>")
      response.write(objErr.HelpFile & "</td></tr>")
      response.write("<tr><td>Native error</td><td>")
      response.write(objErr.NativeError & "</td></tr>")
      response.write("<tr><td>Error number</td><td>")
      response.write(objErr.Number & "</td></tr>")
      response.write("<tr><td>Error source</td><td>")
      response.write(objErr.Source & "</td></tr>")
      response.write("<tr><td>SQL state</td><td>")
      response.write(objErr.SQLState & "</td></tr>")
      response.write("</table><br/><br/>")
    next
else
    <!-- No errors detected, proceed with ASP code -->
end if
%>

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top