0

Why should we close a database connection? what can happen if a connection is left open? does the connection gets closed automatically when app exits?

dreamer1989
  • 1,075
  • 3
  • 12
  • 29

3 Answers3

1

1) Open connections as late as possible

2) Close connections as soon as possible

The connection itself is returned to the connection pool. Connections are a limited resource. Any new connection you establish that has exactly the same connection string will be able to reuse the connection from the pool.

0

It's not really necessary to close your database connection. See this question on stackoverflow for a more detailed explanation.

Community
  • 1
  • 1
Ceetn
  • 2,728
  • 2
  • 25
  • 28
0

To release the resourcess like handler,we should use DBHelper.close(); to close Database, if you not close database,its may arise problem when you try to reconnect to Database. So to overcome this problem , we must close Database.

Rajendra
  • 1,700
  • 14
  • 17