asp.net.ph

SqlConnection.Close Method

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 ( );

Remarks

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.

Example

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 

See Also

SqlConnection Members   Open   StateChange Skip Navigation Links




Home
Suggested Reading


Previous page Back to top Next page

© 2000-2010 Rey Nuñez All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note

You can help support asp.net.ph