Should I close connection to database?
- Should I close DB connection after query?
- What happens if you don't close database connection?
- Should I keep a database connection open?
- Do I need to close SQL connection in using?
Should I close DB connection after query?
Don't close your connection unless you are exiting your app, and then make sure you do. Ensure that you are using the same connection when you come back to do more I/O. Database connections are resource-intensive and should be established as few times as possible and shared as much as possible.
What happens if you don't close database connection?
If you don't close it, it leaks, and ties up server resources. @EJP The connection itself might be thread-safe (required by JDBC), but the applications use of the connection is probably not threadsafe. Think of things like different transaction isolation, boundaries (commit/rollback/autocommit) etc.
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.
Do I need to close SQL connection in using?
If you take the connection outside of the Using statement, then yes - you would need to close the connection when finished. Show activity on this post. No, it is not wrong. The sqlConnection will close the connection after it will pass using block and call Dispose method.
Related Questions
-
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago -
Anonymous2 weeks ago
Expert answer2 weeks ago