Bagikan melalui


IDbConnection.State Properti

Definisi

Mendapatkan status koneksi saat ini.

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

Nilai Properti

Salah ConnectionState satu nilai.

Contoh

Contoh berikut membuat instans kelas turunan, OleDbConnection, mengatur ConnectionString, dan menampilkan 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

Keterangan

Perubahan status yang diizinkan adalah:

  • Dari Closed ke Open, menggunakan Open metode objek Koneksi.

  • Dari Open ke Closed, menggunakan Close metode atau Dispose metode objek Koneksi.

Berlaku untuk