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 statement is being processed, you can return an appropriate message to the user.

The SAConnection class has a State property that can be used to check the state of the connection. Possible state values are Open and Closed.

The following code checks whether the SAConnection 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;
} 
 See also