DB2Connection.State Property
Gets the current state of the connection.
- Namespace:
IBM.Data.DB2
- Assembly:
IBM.Data.DB2
(inIBM.Data.DB2.dll
)
Syntax
[Visual Basic]
Public ReadOnly Property State As ConnectionState Implements _
IDbConnection.State
[C#]
public ConnectionState State {get;}
[C++]
public: __property ConnectionState get_State();
[JScript]
public function get State() : ConnectionState;
- Implements:
- IDbConnection.State
Property value
A bitwise combination of the System.Data.ConnectionState values. The default is Closed.
Remarks
The allowed state changes are:
- From Closed to Open, using the Open method of the DB2®Connection object.
- From Open to Closed, using either the Close method or the Dispose method of the DB2Connection object.
Note: Calling the State property on
an open connection increases application resource usage because each
such call results in an explicit low-level call to determine if the
connection is still valid.
Example
[Visual Basic, C#] The following example creates an instance of a derived class, DB2Connection , sets its ConnectionString, and displays its State.
[Visual Basic]
Public Sub createDB2Connection()
Dim myConnection As New DB2Connection()
myConnection.ConnectionString = _
"DATABASE=SAMPLE;"
myConnection.Open()
MessageBox.Show("Connection State: " + myConnection.State.ToString())
myConnection.Close()
End Sub
[C#]
public void createDB2Connection()
{
DB2Connection myConnection = new DB2Connection();
myConnection.ConnectionString = "DATABASE=SAMPLE;";
myConnection.Open();
MessageBox.Show("Connection State: " + myConnection.State.ToString());
myConnection.Close();
}