Contents Index Transaction processing Deploying the Adaptive Server Anywhere .NET data provider

ASA Programming Guide
  Developing Applications with the .NET Data Provider

Error handling and the Adaptive Server Anywhere .NET data provider


Your application must be designed to handle any errors that occur, including ADO.NET errors. ADO.NET errors are handled within your code in the same way that you handle other errors in your application.

The Adaptive Server Anywhere .NET data provider throws AsaException objects whenever errors occur during execution. Each AsaException object consists of a list of AsaError objects, and these error objects include the error message and code.

Errors are different from conflicts. Conflicts arise when changes are applied to the database. Your application should include a process to compute correct values or to log conflicts when they arise.

For more information about handling conflicts, see Resolving conflicts when using the AsaDataAdapter.

.NET provider error handling example 

The following example is from the Simple sample project. Any errors that occur during execution and that originate with Adaptive Server Anywhere .NET data provider objects are handled by displaying them in a message box. The following code catches the error and displays its message:

catch( AsaException ex ) {
    MessageBox.Show( ex.Errors[0].Message );
}
Connection error handling example 

The following example is from the Table Viewer sample project. If there is an error when the application attempts to connect to the database, the following code uses a try and catch block to catch the error and display its message:

try {
    _conn = new AsaConnection( txtConnectString.Text );
    _conn.Open();
  } catch( AsaException ex ) {
    MessageBox.Show( ex.Errors[0].Source + " : "
     + ex.Errors[0].Message + " (" +
     ex.Errors[0].NativeError.ToString() + ")",
         "Failed to connect" );

For more error handling examples, see Understanding the Simple sample project and Understanding the Table Viewer sample project.

For more information about error handling, see AsaException class and AsaError class.


Contents Index Transaction processing Deploying the Adaptive Server Anywhere .NET data provider