Contents Index Connection pooling Accessing and manipulating data

ASA Programming Guide
  Developing Applications with the .NET Data Provider
    Connecting to a database

Checking the connection state


Once your application has established a connection to the database, you can check the connection state to ensure that the connection is open before you fetch data from the database to update it. If a connection is lost or is busy, or if another command is being processed, you can return an appropriate message to the user.

The AsaConnection class has a state property that checks the state of the connection. Possible state values are Open and Closed.

The following code checks whether the Connection object has been initialized, and if it has, it ensures that the connection is open. A message is returned to the user if the connection is not open.

if( _conn == null || _conn.State !=
  ConnectionState.Open ) {
  MessageBox.Show( "Connect to a database first",
   "Not connected" );
  return;

For more information, see State property.


Contents Index Connection pooling Accessing and manipulating data