Error handling

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

When errors occur during execution, ASE 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.

ASE 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 ASE 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

The following 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

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 “AseException class” and “AseError class”.