共用方式為


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 方法。

適用於