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