IDbConnection.State 属性

定义

获取连接的当前状态。

public:
 property System::Data::ConnectionState State { System::Data::ConnectionState get(); };
public System.Data.ConnectionState State { get; }
member this.State : System.Data.ConnectionState
Public ReadOnly Property State As ConnectionState

属性值

ConnectionState 值之一。

示例

以下示例创建派生类 的实例, OleDbConnection设置其 ConnectionString, 并显示其 State

public void CreateOleDbConnection(){
   OleDbConnection connection = new OleDbConnection();
   connection.ConnectionString =
       "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb";
   Console.WriteLine("Connection State: " + connection.State.ToString());
}
Public Sub CreateOleDbConnection()
    Dim connection As New OleDbConnection()
    connection.ConnectionString = _
       "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=Northwind.mdb"
    Console.WriteLine("Connection State: " & connection.State.ToString())
End Sub

注解

允许的状态更改包括:

  • ClosedOpen,使用 Open Connection 对象的 方法。

  • OpenClosed,使用 Close Connection 对象的 方法或 Dispose 方法。

适用于