The .NET Framework includes two classes in the System.Data.SqlClient namespace that are useful in handling SQL Server errors. The SqlException class exposes an Errors property, which is a collection of SqlError class objects. When an error occurs in data access, it will return an instance of the SqlException class. You can then walk through the Errors collection and react to the returned SqlError objects. For example, to just display any data access errors, you could use a Try / Catch block similar to this one: Try ' Perform SQL Server operations here Catch SqlEx As SqlException ' Handle SQL Server specific errors Dim err As SqlError For Each err In SqlEx.Errors MessageBox.Show("SQL Error " & err.Number & ": " & err.Message) Next Catch Ex As Exception ' Handle general errors MessageBox.Show("Non-SQL Exception " & Ex.Message) End Try In addition to operational errors that may be encountered , when multiple users make changes to data within separate DataSet objects and then attempt to update the values in the data source, the question arises as to which one of the conflicting changes will "win." You can control the resolution of this situation through the UpdateCommand property of a SqlDataAdapter object, which may be configured in one of two ways:
|