3.10. Error Handling

If you need to handle only a single error, you can use the generic Exception class, which reports a single error message. Sometimes, databases return additional error information or a collection of errors. This is especially true of OLE DB, in which each provider can add information when using the service provider architecture. For this reason, SqlClient and OleDb each implements its own subclass of Exception, which can return a collection of errors.

The OleDb provider's OleDbException exposes an OleDbErrorCollection that is similar to the ADO's Errors collection (OLE DB's IErrorRecord). Each error contains an error message, the provider's native error, and an optional SQLState. The OleDbException is derived from InteropServices.ExternalException ...

Get Essential ADO.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.