IDbConnection.State 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得連線目前的狀態。
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
備註
允許的狀態變更如下:
從
Closed
到Open
,使用Open
Connection 物件的 方法。從
Open
到Closed
,使用Close
Connection 物件的 方法或Dispose
方法。