System.Data Namespace IDbConnection Class
Opens a database connection with the property settings specified by the ConnectionString.
[ VB ]
NotOverridable Public Sub Open ( )
[ C# ]
public void Open ( );
[ C++ ]
public: __sealed void Open ( );
[ C++ ]
public function Open ( );
The IDbConnection draws an open connection from the connection pool if one is available. Otherwise, it establishes a new connection to the data source.
NOTE: If the IDbConnection goes out of scope, it is not closed. Therefore, you must explicitly close the connection by calling Close.
The following example initializes and opens an SqlConnection, displays some of its properties, then closes the connection.
protected void Page_Load ( Object Src, EventArgs e ) {
// specify the data source
SqlConnection myConn = new SqlConnection (
"server=( local )\\NetSDK; trusted_connection=yes; database=pubs" );
// open the data connection
myConn.Open ( );
// retrieve properties of the connection object
...
// close the data connection
myConn.Close ( );
}
Show me
IDbConnection Members Close