State Property (SqlConnection)
Gets the current state of the connection.
Property Value
A bitwise combination of the
System.Data.ConnectionState values. The default value is Closed.
The following example creates an instance of a derived class,
SqlConnection, sets its
ConnectionString, and displays its
State.
|
|---|
public void CreateSqlConnection()
{
SqlConnection sqlConnection = new SqlConnection();
sqlConnection.ConnectionString =
"User Id=sa;Server=localhost;Initial Catalog=Test;";
sqlConnection.Open();
MessageBox.Show("Connection State: " + sqlConnection.State.ToString());
sqlConnection.Close();
} |
|
|---|
Public Sub CreateSqlConnection()
Dim sqlConnection As New SqlConnection()
sqlConnection.ConnectionString = _
"User Id=sa;Server=localhost;Initial Catalog=Test;"
sqlConnection.Open()
MessageBox.Show("Connection State: " + sqlConnection.State.ToString())
sqlConnection.Close()
End Sub |