473,396 Members | 1,775 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,396 software developers and data experts.

How Many SQL Connections Should I Use?

Hello,

I was wondering what the best practices are as far as how many
connections one should use for a data-driven app. Here's my situation:
I have a business object that I load data into, this object also has 3
collections which I also load data into (via their own method). Right
now each method has its own connection that uses a datareader to add
the items to the collection. I can't use the same connection between
the parent object and my 3 collections because datareaders require
their own connection. Is it ok to open 4 seperate connections just to
load one object of data?

What is the best practice? Anybody have any links where this situation
is discussed? Any help would be appreciated. Thanks!

Mar 15 '06 #1
3 984
Once each collection finish loading its data - wouldn't it close the
datareader? In which case, you would never have a situation where code was
trying to use a connection that still had an active datareader on it.

Regardless of this, each method that needs to load data should open up a
connection, get its data, and close the connection. The connection should
not hang around in an open state if it's not being used.

"db.guru" <aa*********@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...
Hello,

I was wondering what the best practices are as far as how many
connections one should use for a data-driven app. Here's my situation:
I have a business object that I load data into, this object also has 3
collections which I also load data into (via their own method). Right
now each method has its own connection that uses a datareader to add
the items to the collection. I can't use the same connection between
the parent object and my 3 collections because datareaders require
their own connection. Is it ok to open 4 seperate connections just to
load one object of data?

What is the best practice? Anybody have any links where this situation
is discussed? Any help would be appreciated. Thanks!

Mar 15 '06 #2
Well, the collection loading happens within the main object, which uses
a connection and a datareader to load its own data. I suppose I could
close the main object's datareader before loading each collection. (not
sure why I didn't consider that initially...).

So it's not too resource intensive to open and close a connection for
each method that loads data?

Mar 15 '06 #3
My understanding (and I would welcome being corrected) is that if you
open a new connection using the same connection string as an existing,
open connection then connection pooling kicks in. Which would mean that
you wouldn't be opening a new connection, rather using an existing one.

E.g.

- Open Connection_A and use it for something.
- Meanwhile Open Connection_B (which will actually use the same
connection as Open Connection_A).
- Close Connection_B - A is in use so it stays open
- Close Connection_A - no more connections in use so it closes properly

Now, if you are frequently opening and then closing just one connection,
I don't quite see how connection pooling can help. I've tried connecting
to Access (albeit with ADO 2.7 not ADO.NET) and noticed it's
significantly slower if you keep opening and reopening a connection
rather than keeping it open.

I haven't tested it yet with SQL Server (I shall tomorrow) but I have
been informed that when you connect to Oracle (again not .NET) the
server assigns resources to that connection. If you close and reopen
just one connection (i.e. avoiding pooling) you take up fresh resources
from the server since it doesn't tidy up instantly.

Again: this is my understanding. Someone please speak up if this is
nonsense.

db.guru wrote:
Well, the collection loading happens within the main object, which uses
a connection and a datareader to load its own data. I suppose I could
close the main object's datareader before loading each collection. (not
sure why I didn't consider that initially...).

So it's not too resource intensive to open and close a connection for
each method that loads data?

Mar 16 '06 #4

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

Similar topics

3
by: Randell D. | last post by:
Folks, I currently connect to my db with PHP code that uses non-persistent connections. I've read that persistent connections can help performance since a connection to the db will use an...
3
by: Mudge | last post by:
Hi, My hosting provider only allows me to use 50 connections to my MySQL database that my Web site will use. I don't know what this 50 connections means exactly. Does this mean that only 50...
4
by: Angelos | last post by:
I get this error mysql_pconnect Too many connections ... every now and then. Does anyone knows where it comes from ? There are a lot of sites running on the server and all of them use the...
1
by: C Sharp beginner | last post by:
I'm sorry about this verbose posting. This is a follow-up to my yesterday's posting. Thanks William for your reply. I understand it is a good practice to open connections as late as possible and...
2
by: Bob | last post by:
We have a production web site that's data intensive (save user input to DB and query for displaying) with the ASP.NET app part on one W2K server and SQL 2000 DB on another W2K server. I have set...
17
by: Peter Proost | last post by:
Hi Group, I've got an interesting problem, I don't know if this is the right group but I think so because everything I've read about it so far says it's a .net problem. Here's the problem, we're...
4
by: elyob | last post by:
Not really tried going two ways at once, but I have an include_once connection to a mysql_database, now I need to retrieve info from a second mysql_database .. My mysql_connects are getting...
1
by: marcfischman | last post by:
Please help. I have a website running on a linux/apache/mysql/php server. I receive about 8,000-10,000 visitors a day with about 200,000 to 300,000 page views. The server is a RedHat Linux...
13
by: PRP | last post by:
Hi, Our DBA has complained about the large number of connections from the aspnet_wp process. We have multiple web applications deployed in different virtual directories. I read that the way...
5
by: Usman Jamil | last post by:
Hi I've a class that creates a connection to a database, gets and loop on a dataset given a query and then close the connection. When I use netstat viewer to see if there is any connection open...
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
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.