•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the ASP.NET section within the Web Development category of DaniWeb, a massive community of 456,526 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,807 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our ASP.NET advertiser: Lunarpages ASP Web Hosting
Views: 1688 | Replies: 3
![]() |
| |
•
•
Join Date: Sep 2007
Posts: 1,058
Reputation:
Rep Power: 4
Solved Threads: 61
What is better to do, and if you could, please include the pros and cons along with your opinions:
1) Open the connection to the database as late as possible and end it as early as possible, and do this a total of 5 times in one page_load.
2) Open the connection to the database as late as possible and KEEP it OPEN until the last SQL Query has been retreieved, then close it.
3) Split the connections; Keep one Connection open for 2 or 3 query executes and then close, then open another and execute the remaining.
I believe number 2 is the best, as if 100 people access the page at once, that would create 100 connections in the matter of seconds, rather than option one of creating 500 connections in the matter of seconds. But does leaving the connections open use up more memory and drain more performance than just having 500 connections? Or does it really matter? Let me know.
1) Open the connection to the database as late as possible and end it as early as possible, and do this a total of 5 times in one page_load.
2) Open the connection to the database as late as possible and KEEP it OPEN until the last SQL Query has been retreieved, then close it.
3) Split the connections; Keep one Connection open for 2 or 3 query executes and then close, then open another and execute the remaining.
I believe number 2 is the best, as if 100 people access the page at once, that would create 100 connections in the matter of seconds, rather than option one of creating 500 connections in the matter of seconds. But does leaving the connections open use up more memory and drain more performance than just having 500 connections? Or does it really matter? Let me know.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,541
Reputation:
Rep Power: 40
Solved Threads: 972
Opening a database is expensive in terms of both time and resources. So the fewer times you have to open it the better performace your program will achieve. I would opt for option #2. Of course one problem is that you may need to tell the database server to flush the data to disk often. But a good database server will probably do that anyway. The programs I worked with each user had his/her own connection, for security reasons. The connection was opened when the user logged onto the application program and was not closed until the user logged off. There was no more than 8 hours between logon and logoff (one 8 hour shift). One problem we had to overcome was accidental dropped connections do to network down or server down.
•
•
Join Date: May 2006
Location: Bellevue, WA
Posts: 1,548
Reputation:
Rep Power: 8
Solved Threads: 51
Option 2, closing after the last query for the page load (which may be automatic anyways, when everything is GC'ed). The overhead of opening and closing the connections for a single load will always be more than keeping an idle connection for processing 1 request. If you want to keep it around longer than that, there may be security ramifications, as AD suggested.
![]() |
•
•
•
•
•
•
•
•
DaniWeb ASP.NET Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
.net .net framework 3.0 access adsl adsl1 adsl2 adsl2+ ajax asp avatar backup breach cable code combo connection custom daniweb data data protection database design developer development dropdownlist government hacker ibm internet medicine microsoft module net news normalization office reuse second security server skin software sql survey theme upload vista web windows workflow 240000
- database connection(select ,insert query) within javascript function (JSP)
- Problem with database connection (JSP)
- Visual C++, Database connection, please help (C++)
- script problem adding to database (PHP)
- database close() in java (Java)
- Login and retrieve user data from database (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: Alert Notification functionality like Outlook's reminder
- Next Thread: sample message box.



Hybrid Mode