Error Handling

Your application must be designed to handle any errors that occur, including ADO.NET errors.

When errors occur during execution, Adaptive Server ADO.NET Data Provider throws AseException objects. Each AseException object consists of a list of AseError objects, and these error objects include the error message and code. In addition, other exceptions are possible, such as IndexOutOfRangeException and NotSupportedException.

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

Adaptive Server ADO.NET Data 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 ADO.NET Data Provider objects are handled by displaying them in a message box. The following code catches the error and displays its message.

For C#:

catch( AseException ex )
{
   MessageBox.Show( ex.Message ); 
}

For Visual Basic .NET:

Catch ex As AseException
   MessageBox.Show(ex.Message)
End Try

Connection Error-Handling Example

This example is from the Table Viewer sample project. If an error occurs 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:

For C#:

try 
{
   _conn = new AseConnection(
      txtConnectString.Text );
   _conn.Open();
} 
catch( AseException ex ) 
{
   MessageBox.Show(ex.Message, "Failed to connect");
}

For Visual Basic .NET:

Try
   Dim  _conn As New AseConnection( _
      txtConnectString.Text )
   conn.Open()
Catch ex As AseException
   MessageBox.Show(ex.Message, "Failed to connect")
End Try
Related concepts
Understand Simple Sample Project
Understand Table Viewer Sample Project
AseException Class
AseError Class