This documentation is archived and is not being maintained.

IDbConnection.State Property

Gets the current state of the connection.

[Visual Basic]
ReadOnly Property State As ConnectionState
[C#]
ConnectionState State {get;}
[C++]
__property ConnectionState get_State();
[JScript]
function get State() : ConnectionState;

Property Value

One of the ConnectionState values.

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.

Example

[Visual Basic, C#, C++] The following example creates an instance of a derived class, OleDbConnection, sets its ConnectionString, and displays its State.

[Visual Basic] 
Public Sub createOleDbConnection()
    Dim myConnection As New OleDbConnection()
    myConnection.ConnectionString = _
       "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB"
    MessageBox.Show("Connection State: " + myConnection.State.ToString())
End Sub

[C#] 
public void createOleDbConnection(){
   OleDbConnection myConnection = new OleDbConnection();
   myConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB";
   MessageBox.Show("Connection State: " + myConnection.State.ToString());
}

[C++] 
public:
 void createOleDbConnection(){
    OleDbConnection* myConnection = new OleDbConnection();
    myConnection->ConnectionString = S"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=NWIND_RW.MDB";
    MessageBox::Show(String::Format( S"Connection State: {0}", __box(myConnection->State)));
 }

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

IDbConnection Interface | IDbConnection Members | System.Data Namespace

Show: