Handling Errors

Errors in ADO.NET are handled the same way as elsewhere in the .NET framework—you can catch exceptions that are thrown by objects involved in connecting to and interacting with the database.

The tricky thing about dealing with errors in data-access programming is that so many things can go wrong at various stages in each request. The programmer can phrase the command in a syntactically incorrect way; the network connection can be bad; the database server can be on vacation. So it's useful in database programming to have a rich collection of error messages from every element in every database call.

ADO.old provided this in the form of an Errors collection associated with the database connection object. In ADO.NET, you are given ...

Get C#® Developer's Guide to ASP.NET, XML, and 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.