Another question i asked..
Closing a conneciton in the "unload" method
Has piqued my interest in the subject. When relating to asp.net/c# I understand that there is an underlying expense in opening/closing database connections, I’m interested in whether it’s more expensive to either…
- Open DB connection at the start of a request
- Do several operations
- close connection at end or the request
vs
- Open connection directly before any database command
- Close straight away
(thus opening and closing connections several time during a request)
If anyone could provide any insight, or point me in the direction of some reading material on the matter, that would be awesome.
You may find the following links useful. They point to Microsoft’s best practices implementing Data Access Layer:
I agree with Steve that, in most cases, you should keep connection open for the shortest time possible.
From my experience, I used to re-work code that was using opened connections for extended periods of time and that caused licensing problems (number of concurrent users).