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 on how we can loop through the
Errors Collection:
Syntax
objErr.property
Properties
Property | Description |
Description | Returns an error description |
HelpContext | Returns the context ID of a topic in the Microsoft Windows help system |
HelpFile | Returns the full path of the help file in the Microsoft Windows help system |
NativeError | Returns an error code from the provider or the data source |
Number | Returns a unique number that identifies the error |
Source | Returns the name of the object or application that generated the error |
SQLState | Returns 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
%>
Did you find the page informational and useful? Share it using one of your favorite social sites.
Recommended Books & Training Resources