Article ID: 167957 - Last Review: March 2, 2005 - Revision: 2.2 INFO: Extracting Error Information from ADO in VBThis article was previously published under Q167957 SUMMARY
When ActiveX Data Objects (ADO) encounter an error, often the Errors
Collection is filled with details on the cause of the error. This article
provides sample code for extracting the maximum possible information on any
errors raised by ADO using Visual Basic. If ADO itself encounters an error, it does not populate the Errors Collection, but instead you have to use a native error mechanism to catch and display the error, in this case the Visual Basic Err object. If the provider or underlying components generate error, then these will be populated in the ADO Errors Collection. So you need to check both the Visual Basic Error object and the ADO Errors Collection. However, you may want to preserve the values of the Err collection, because if you Error handling is too complex, in the process of examining and displaying the Errors collection, you could end up resetting the Err object. MORE INFORMATION
The documentation for the ADO Error object indicates that the Errors
Collection will be populated if any error occurs within ADO or it's
underlying provider. This is somewhat incorrect. Depending on the source of
the error, or even bug, in the underlying provider to ADO (OLE-DB) or
within ADO itself, the errors collection may not be populated. You need to
check both the Visual Basic Error object as well as the ADO Errors collection. The Errors Collection is only available from the Connection object, so you need to initialize ADO off of a Connection object. Following is sample code that demonstrates how to open a connection and report any errors encountered. Often the Errors Collection returns an HRESULT in either hexadecimal format (for example, 0x80004005) or as a long value (for example, 2147467259). These HRESULTS can be raised by underlying components such as OLE-DB or even OLE itself. When this is the case, it may be confusing since these codes are not documented in the ADO online documentation. However, frequently encountered HRESULTS can be found in the Microsoft Knowledge Base article listed in the REFERENCES section. REFERENCES
For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
168335
(http://support.microsoft.com/kb/168335/EN-US/
)
INFO: Using ActiveX Data Objects (ADO) via Visual Basic
168354
(http://support.microsoft.com/kb/168354/EN-US/
)
INFO: Underlying OLE and OLEDB Provider Errors Are Exposed Through ADO
APPLIES TO
| Article Translations
|
Back to the top
