473,387 Members | 1,687 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Is it better to open connection with DB at beginning and close at end, or after every "object run"?

Sorry for the English.
I mean, when building my applications, I often need to do several
database actions, and I'm thinking, what's better?

1) Open connection with DB, for instance mySQL, at beginning and close
at the end, so every "unit" in the code knows that THIS IS the
connection, and its opened.

OR

2) Every "unit" in the code opens and closes DB connection
independantly.

Jan 11 '06 #1
2 1579
3) The database object/connection is created as soon as it is needed and
passed to all units that need it. This allows reuse of the units.

Best regards

Rafi B. wrote:
Sorry for the English.
I mean, when building my applications, I often need to do several
database actions, and I'm thinking, what's better?

1) Open connection with DB, for instance mySQL, at beginning and close
at the end, so every "unit" in the code knows that THIS IS the
connection, and its opened.

OR

2) Every "unit" in the code opens and closes DB connection
independantly.

Jan 11 '06 #2
d
"Dikkie Dik" <no****@nospam.org> wrote in message
news:dq**********@news.cistron.nl...
3) The database object/connection is created as soon as it is needed and
passed to all units that need it. This allows reuse of the units.
Ideally, it should use persistent connections (if the server allows), and
the object shouldn't initiate its connection to the DB unless it's passed a
query (so don't do it when the object is constructed, but when it's actually
used).

Best regards

Rafi B. wrote:
Sorry for the English.
I mean, when building my applications, I often need to do several
database actions, and I'm thinking, what's better?

1) Open connection with DB, for instance mySQL, at beginning and close
at the end, so every "unit" in the code knows that THIS IS the
connection, and its opened.

OR

2) Every "unit" in the code opens and closes DB connection
independantly.

Jan 12 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Hung Jung Lu | last post by:
Hi, Does anybody know where this term comes from? "First-class object" means "something passable as an argument in a function call", but I fail to see the connection with "object class" or...
2
by: Jenna Olson | last post by:
Hi all- I've never seen this particular issue addressed, but was wondering if there's anything to support one way or another. Say I have a class: class ManipulateData { public:...
2
by: brazilnut52 | last post by:
I am going to outline the steps I go through to produce the problem. Hopefully this will help you understand the problem better I have created a simple COM DLL in .NET by using the COM class...
7
by: Ryan Park | last post by:
Hi, //SITUATION I got a panel control that hold a certain position on a form. Every controls or UIs are on this panel. At certain situation, I called dispose() method of this panel control...
7
by: Bennett Haselton | last post by:
Is there any way to find a string representing an object's class, which will work in Internet Explorer 6? "typeof" doesn't work -- it returns "object" for all objects: x =...
3
by: Steve Lutz | last post by:
Hi All, I have a Windows Service that runs well. The service hosts a remote object. The purpose of the object is so that I can "peak" into the service to see what it's doing. I wrote a small...
1
by: aaa | last post by:
I am using a third party provider for Travel related web services. These services are not very well documented and I am having to wing my way thru nearly every one. Some I can pull data from...
4
by: lars.uffmann | last post by:
Hey everyone! I am (still) working on a project that I took over from former students, so don't blame me for the criminal approach on coding *g* The problem I have is fairly easy and while I...
5
by: dotnetnovice | last post by:
Hi everybody actually i was trying to insert some records in to SQL server through C# Wndows Aplication and during that i face an error "Object reference not set to an instance of an object." and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.