Closing a Database Connection
Once an application is finished using an open connection, that connection should be closed. Some APIs automatically close connections when the application exits; however, it is best to explicitly close the connection as soon as the application is finished accessing the database to allow other applications access to precious connection resources.
Tip
Calling the appropriate close methods when finished with an ADO.NET or JDBC object is essential to freeing precious database resources used by the application. Both ADO.NET and Java offer very few guarantees when objects are finalized; therefore, it is common for those applications that don’t close objects explicitly to run out of database resources (such as connections, statement handles, and memory).
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access