Bewerken

Delen via


Error Object

Contains details about data access errors that pertain to a single operation involving the provider.

Remarks

Any operation involving ADO objects can generate one or more provider errors. As each error occurs, one or more Error objects are placed in the Errors collection of the Connection object. When another ADO operation generates an error, the Errors collection is cleared, and the new set of Error objects is placed in the Errors collection.

Note

Each Error object represents a specific provider error, not an ADO error. ADO errors are exposed to the run-time exception-handling mechanism. For example, in Microsoft Visual Basic, the occurrence of an ADO-specific error will trigger an On Error event and appear in the Error object. For a complete list of ADO errors, see the ErrorValueEnum topic.

You can read an Error object's properties to obtain specific details about each error, including the following:

  • The Description property, which contains the text of the error. This is the default property.

  • The Number property, which contains the Long integer value of the error constant.

  • The Source property, which identifies the object that raised the error. This is particularly useful when you have several Error objects in the Errors collection following a request to a data source.

  • The SQLState and NativeError properties, which provide information from SQL data sources.

When a provider error occurs, it is placed in the Errors collection of the Connection object. ADO supports the return of multiple errors by a single ADO operation to allow for error information specific to the provider. To obtain this rich error information in an error handler, use the appropriate error-trapping features of the language or environment you are working with, then use nested loops to enumerate the properties of each Error object in the Errors collection.

Note

Microsoft Visual Basic and VBScript Users If there is no valid Connection object, you will need to retrieve error information from the Error object.

Just as providers do, ADO clears the OLE Error Info object before making a call that could potentially generate a new provider error. However, the Errors collection on the Connection object is cleared and populated only when the provider generates a new error, or when the Clear method is called.

Some properties and methods return warnings that appear as Error objects in the Errors collection but do not halt a program's execution. Before you call the Resync, UpdateBatch, or CancelBatch methods on a Recordset object; the Open method on a Connection object; or set the Filter property on a Recordset object, call the Clear method on the Errors collection. That way, you can read the Count property of the Errors collection to test for returned warnings.

The Error object is not safe for scripting.

This section contains the following topic.

See Also

Description, HelpContext, HelpFile, NativeError, Number, Source, and SQLState Properties Example (VB)
Description, HelpContext, HelpFile, NativeError, Number, Source, and SQLState Properties Example (VC++)
Connection Object (ADO)
Errors Collection (ADO)
Appendix A: Providers