Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Database and Reporting > Style or Best Practice question


Reply
 
Thread Tools Display Modes
  #1  
Old 10-06-2004, 10:11 AM
leebarnard leebarnard is offline
Regular
 
Join Date: Oct 2003
Location: Boca Raton, FL
Posts: 51
Default Style or Best Practice question


Is it better to open an ADO connection object at the start of the application and keep it open throught the life of the app or is it better to open when needed and close when done?

Are there performance issues with either method?
Reply With Quote
  #2  
Old 10-06-2004, 10:48 AM
Bart1123 Bart1123 is offline
Contributor
 
Join Date: Mar 2003
Location: Oklahoma City, OK
Posts: 455
Default

I have read in many instances, in the forum, that the best practice is to open the ADO connection, get the information you need and then close it. From personal expierience I agree with this method. I am unaware of any performance issues with either method, I have inherited several apps where this practice is not used and have not seen any difference in app speed. However opening a connection only as long as you need it makes the code easier to follow in my opinion.

just my CHF.02524

Bart
__________________
"I have not failed. I've just found 10,000 ways that won't work." - Thomas Alva Edison
Want a Gmail Account? Forum Members only please. Email me with your forum nick :)
Reply With Quote
  #3  
Old 10-06-2004, 12:05 PM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

It really depends upon the situation.

If your requirements stress response time, including connection time, over all else, then open the connection and leave it open for the life of your app.

If you are limited in the number of connections, either through server licensing issues, throughput throttling (as with MSDE,) multiple user limits (as with Access) or server resource limitations (any server based database, as each connection requires memory and/or processing) then you evaluate the life of your connections in your design. This is the case in most business situations, btw.
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
Reply With Quote
  #4  
Old 10-06-2004, 12:39 PM
Gary Gary is offline
Freshman
 
Join Date: Jul 2003
Location: Blue Springs, MO
Posts: 32
Default

I asked a similar question some time ago. Check it out here.

Unless I need to keep the connection open, like to update or delete multiple items, I never open a connection. (See the example in the above post.)

--Gary
Reply With Quote
  #5  
Old 10-06-2004, 02:24 PM
leebarnard leebarnard is offline
Regular
 
Join Date: Oct 2003
Location: Boca Raton, FL
Posts: 51
Default

I have dont it both ways and it of-course works I was just never sure what was the "proper" way of doing it. Frankly I assumed that opening and closing a connection every time i needed to query would cause unnecessary overhead. I believe you guys are telling me that is not necessarily the case but it is more appropriate to open when it you need it and close it when done.
__________________
I predict future happiness for Americans if they can prevent the government from wasting
the labors of the people under the pretense of taking care of them. -- Thomas Jefferson
The person who would give up even one freedom in the name of security deserves neither
freedom nor security. -- Thomas Jefferson
Reply With Quote
  #6  
Old 10-06-2004, 09:37 PM
HardCode's Avatar
HardCode HardCode is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Feb 2004
Location: New Jersey
Posts: 3,338
Default

Also, licensing will determine the way for you to do it. Usually, a license is for X number of concurrent connections. If you have many users and few connections, then opening the connection, doing your thing, then closing it, will allow you to have many more people "virtually simultaneously" access the DB. All within that type of license agreement.

Think of having Microsoft SQL Server as a back end. You can run a web site with a 25 user license, but you don't need 8 gazillion licenses because a connection is only made for the loading of a page. Then it closes and is available for another user.
__________________
DON'T CLICK HERE

Useful forum tags: [VB][/VB], [CODE][/CODE], [HTML][/HTML]
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->