







![]() ![]() |
MySQL Connector/Net |
MySqlConnection..::..State Property |
MySqlConnection Class Example See Also Send Feedback |
![]() |
Gets the current state of the connection.
Namespace: MySql.Data.MySqlClient
Assembly: MySql.Data (in MySql.Data.dll) Version: 6.8.4.0
Syntax
C# |
---|
public override ConnectionState State { get; } |
Visual Basic |
---|
Public Overrides ReadOnly Property State As ConnectionState Get |
Visual C++ |
---|
public: virtual property ConnectionState State { ConnectionState get () override; } |
Return Value
A bitwise combination of the ConnectionState values. The default is Closed.Implements
IDbConnection..::..State
Remarks
The allowed state changes are:
- From Closed to Open, using the Open method of the connection object.
- From Open to Closed, using either the Close method or the Dispose method of the connection object.
Examples
The following example creates a MySqlConnection, opens it,
displays some of its properties, then closes the connection.
Visual Basic | ![]() |
---|---|
Public Sub CreateMySqlConnection(myConnString As String) Dim myConnection As New MySqlConnection(myConnString) myConnection.Open() MessageBox.Show("ServerVersion: " + myConnection.ServerVersion _ + ControlChars.Cr + "State: " + myConnection.State.ToString()) myConnection.Close() End Sub |
C# | ![]() |
---|---|
public void CreateMySqlConnection(string myConnString) { MySqlConnection myConnection = new MySqlConnection(myConnString); myConnection.Open(); MessageBox.Show("ServerVersion: " + myConnection.ServerVersion + "\nState: " + myConnection.State.ToString()); myConnection.Close(); } |