 |

10-06-2004, 10:11 AM
|
|
Regular
|
|
Join Date: Oct 2003
Location: Boca Raton, FL
Posts: 51
|
|
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?
|
|

10-06-2004, 10:48 AM
|
|
Contributor
|
|
Join Date: Mar 2003
Location: Oklahoma City, OK
Posts: 455
|
|
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 :)
|

10-06-2004, 12:05 PM
|
 |
Google Hound
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
|
|
|
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
|

10-06-2004, 12:39 PM
|
|
Freshman
|
|
Join Date: Jul 2003
Location: Blue Springs, MO
Posts: 32
|
|
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
|
|

10-06-2004, 02:24 PM
|
|
Regular
|
|
Join Date: Oct 2003
Location: Boca Raton, FL
Posts: 51
|
|
|
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
|

10-06-2004, 09:37 PM
|
 |
Ultimate Contributor
Forum Leader * Expert *
|
|
Join Date: Feb 2004
Location: New Jersey
Posts: 3,338
|
|
|
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]
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|