System.Data.SqlClient Namespace SqlConnection Class
Closes the connection to the data source. This is the preferred method of closing any open connection.
[ VB ]
NotOverridable Public Sub Close ( )
[ C# ]
public void Close ( );
[ C++ ]
public: __sealed void Close ( );
[ C++ ]
public function Close ( );
The Close method rolls back any pending transactions. It then releases the connection to the connection pool, or closes the connection if connection pooling is disabled. If Close is called while handling a StateChange event, no additional StateChange events are fired.
An application can call Close more than one time. No exception is generated.
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 (
"Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" +
Server.MapPath ( "~/app_data/pubs.mdb" ) );
// open the data connection
myConn.Open ( );
// retrieve properties of the connection object
...
// close the data connection
myConn.Close ( );
}
Show me
SqlConnection Members Open StateChange