Anonymous Asked in Cars &Transportation · 2 weeks ago

Should I keep a database connection open?

Absolutely it is safe to do this. This is how client-server applications work. If you are using a three-tier application, the application server will keep a pool of connections open anyway. 23 нояб. 2008 г.


Should I keep DB connection open or close?

For fast response time and high throughput, it's actually best to keep database connections open and reuse them for subsequent requests. Most database frameworks offer some kind of connection pool mechanism where a request handler can get a database connection for its work and return it to the pool afterwards.

Should I close connection to database?

If you do not close your database connections, many problems can occur like web pages hanging, slow page loads, and more. Think of it as going through a door to your house. Maybe the door will shut by itself, but maybe it won't. If it doesn't shut, who knows what will happen.

What happens if you don't close a database connection?

If we don't close the connection, it will lead to connection memory leakage. Until application server/web server is shut down, connection will remain active, even if the user logs out. There are additional reasons. Suppose database server has 10 connections available and 10 clients request for the connection.

When should I open a database connection?

Usually you'd only want to open a connection to your database when you need to use that connection. Keeping connections open can increase the chance that part of your code will accidentally, or maliciously through the actions of others, cause unwanted queries to be performed on the database.

Related Questions

Relevance
Write us your question, the answer will be received in 24 hours