Open Method (SqlConnection)
Opens a SQL Server connection with the property settings specified by the
ConnectionString.
The following example creates a
SqlConnection, opens it, displays some of its properties, and then closes the connection.
|
|---|
public void CreateSqlConnection(string myConnString)
{
SqlConnection sqlConnection = new SqlConnection(myConnString);
sqlConnection.Open();
MessageBox.Show("ServerVersion: " + sqlConnection.ServerVersion
+ "\nState: " + sqlConnection.State.ToString());
sqlConnection.Close();
} |
|
|---|
Public Sub CreateSqlConnection(myConnString As String)
Dim sqlConnection As New SqlConnection(myConnString)
sqlConnection.Open()
MessageBox.Show("ServerVersion: " + sqlConnection.ServerVersion _
+ ControlChars.Cr + "State: " + sqlConnection.State.ToString())
sqlConnection.Close()
End Sub |