473,505 Members | 16,332 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ADO.NET connections

PRP
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 ADO.NET in-built connection pool works
is per app domain. So in a scenario where I am using single connection
string (from web.config) and I am closing all connections as
recommended, is it correct to assume that ideal number of connections
from aspnet_wp process should be equal to the number of Asp.net web
applications that I configured?

Thanks for your help.

Dec 14 '06 #1
13 1744
"Manish Bafna" <Ma*********@discussions.microsoft.comwrote in message
news:13**********************************@microsof t.com...
I would suggest you implement singleton pattern for having just single
connection thoughout the application.

You have said that you are using single connnection string but there can
be
many connections open.So best practice is to have single connection open
through out the application by implementing singleton pattern
I couldn't disagree more!

Under no circumstances do that! A singleton pattern is not appropriate at
all for connections. IMO, you should only use singletons when you really
need to, e.g. for.queuing or synchronisation. Singletons can cause
concurrency/multithreading issues as well as performance bottlenecks,
especially with regards to database connections.

IMO, you should instantiate a connection only when needed, and destroy it as
soon as you're finished with it. ADO.net uses connection pooling to minimise
the creation of new connections. Keep the duration of database connections
as short as possible so that the connection is returned to the connection
pool where it can be used by the next database transaction.

A singleton pattern, by definition, uses static variables - like Highlander,
there can be only one - that's what 'singleton' means, so every user of the
website uses the same connection all the time - best hope you only have one
concurrent user of your site... In addition, a singleton pattern connection
object would not be scalable up to a web gardening or web farming
architecture.

http://www.velocityreviews.com/forum...plication.html
Dec 14 '06 #2

Thanks for the replies.
>
IMO, you should instantiate a connection only when needed, and destroy it as
soon as you're finished with it. ADO.net uses connection pooling to minimise
the creation of new connections. Keep the duration of database connections
as short as possible so that the connection is returned to the connection
pool where it can be used by the next database transaction.
This is exactly what we are doing in our applications. But now we are
experiencing lot of connection being open from aspnet_wp in our Oracle
database. While we identify/correct the possible long running
tasks/programming mistakes that can cause this issue, what I should be
saying to DBA as expected when he queries for v$sessions. That is
where I am confused. If I have four web apps running in IIS, connecting
to Oracle with same connection string, the ideal number of connections
at any point should be four, am I right??

Dec 14 '06 #3
<p.*********@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
This is exactly what we are doing in our applications.
Glad to hear it.
But now we are experiencing lot of connection being open from aspnet_wp
in our Oracle database.
I'd imagine so - that's the whole point. Lots of very short connections as
opposed to a few long connections or, even worse, one persistent connection.
While we identify/correct the possible long running tasks/programming
mistakes
that can cause this issue, what I should be saying to DBA as expected when
he
queries for v$sessions.
I'd tell him that this is to be expected - what is his problem, AAMOI...?
That is where I am confused. If I have four web apps running in IIS,
connecting
to Oracle with same connection string, the ideal number of connections at
any
point should be four, am I right??
Er, no! The number of *connection pools* should be four.

When a connection is first opened, a connection pool is created based on an
exact matching algorithm that associates the pool with the connection string
in the connection. Each connection pool is associated with a distinct
connection string. When a new connection is opened, if the connection string
is not an exact match to an existing pool, a new pool is created.
Connections are pooled per process, per application domain, per connection
string and when using integrated security, per Windows identity.

When a pool is created, multiple connection objects are created and added to
the pool up to the minimum pool size value. Connections are added to the
pool as needed, up to the maximum pool size specified (default = 100).
Connections are released back into the pool when they are closed or
disposed.

When a SqlConnection object is requested, it is obtained from the pool if a
usable connection is available. To be usable, a connection must be unused,
have a matching transaction context or be unassociated with any transaction
context, and have a valid link to the server. I'd imagine this is the same
for Oracle, but don't know - sorry...
The connection pooler satisfies requests for connections by reallocating
connections as they are released back into the pool. If the maximum pool
size has been reached and no usable connection is available, the request is
queued. The pooler then tries to reclaim any connections until the timeout
is reached (default = 15 seconds). If the pooler cannot satisfy the request
before the connection times out, an exception is thrown.
Dec 14 '06 #4
PRP
While we identify/correct the possible long running tasks/programming
mistakes
that can cause this issue, what I should be saying to DBA as expected when
he
queries for v$sessions.

I'd tell him that this is to be expected - what is his problem, AAMOI...?
Sorry,I missed the important part; he was talking about connections
with status "INACTIVE" in v$sessions.
When a pool is created, multiple connection objects are created and added to
the pool up to the minimum pool size value. Connections are added to the
pool as needed, up to the maximum pool size specified (default = 100).
Connections are released back into the pool when they are closed or
disposed.
Thanks for the detailed explanation, and clearing my doubts.
but at what moment in this process oracle gives the status as
"Inactive"?

Dec 14 '06 #5
"PRP" <pr*******@gmail.comwrote in message
news:11********************@j72g2000cwa.googlegrou ps.com...
While we identify/correct the possible long running tasks/programming
mistakes
that can cause this issue, what I should be saying to DBA as expected
when
he
queries for v$sessions.

I'd tell him that this is to be expected - what is his problem, AAMOI...?

Sorry,I missed the important part; he was talking about connections
with status "INACTIVE" in v$sessions.
Ah...
>When a pool is created, multiple connection objects are created and added
to
the pool up to the minimum pool size value. Connections are added to the
pool as needed, up to the maximum pool size specified (default = 100).
Connections are released back into the pool when they are closed or
disposed.

Thanks for the detailed explanation, and clearing my doubts.
but at what moment in this process oracle gives the status as
"Inactive"?
Er, when they're inactive i.e. not being used for anything... Each
connection pool has a minimum number of connections which are created when
the pool is first created.
Dec 14 '06 #6
Thanks for that. Good read.
Peter

"Mark Rae" <ma**@markNOSPAMrae.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
<p.*********@gmail.comwrote in message
news:11**********************@73g2000cwn.googlegro ups.com...
>This is exactly what we are doing in our applications.

Glad to hear it.
>But now we are experiencing lot of connection being open from aspnet_wp
in our Oracle database.

I'd imagine so - that's the whole point. Lots of very short connections as
opposed to a few long connections or, even worse, one persistent
connection.
>While we identify/correct the possible long running tasks/programming
mistakes
that can cause this issue, what I should be saying to DBA as expected
when he
queries for v$sessions.

I'd tell him that this is to be expected - what is his problem, AAMOI...?
>That is where I am confused. If I have four web apps running in IIS,
connecting
to Oracle with same connection string, the ideal number of connections at
any
point should be four, am I right??

Er, no! The number of *connection pools* should be four.

When a connection is first opened, a connection pool is created based on
an exact matching algorithm that associates the pool with the connection
string in the connection. Each connection pool is associated with a
distinct connection string. When a new connection is opened, if the
connection string is not an exact match to an existing pool, a new pool is
created. Connections are pooled per process, per application domain, per
connection string and when using integrated security, per Windows
identity.

When a pool is created, multiple connection objects are created and added
to the pool up to the minimum pool size value. Connections are added to
the pool as needed, up to the maximum pool size specified (default = 100).
Connections are released back into the pool when they are closed or
disposed.

When a SqlConnection object is requested, it is obtained from the pool if
a usable connection is available. To be usable, a connection must be
unused, have a matching transaction context or be unassociated with any
transaction context, and have a valid link to the server. I'd imagine this
is the same for Oracle, but don't know - sorry...
The connection pooler satisfies requests for connections by reallocating
connections as they are released back into the pool. If the maximum pool
size has been reached and no usable connection is available, the request
is queued. The pooler then tries to reclaim any connections until the
timeout is reached (default = 15 seconds). If the pooler cannot satisfy
the request before the connection times out, an exception is thrown.


Dec 14 '06 #7
>
Er, when they're inactive i.e. not being used for anything... Each
connection pool has a minimum number of connections which are created when
the pool is first created.
Really? I have never seen this before, only connections open on demand.

Thanks for the detailed explanation, and clearing my doubts.
but at what moment in this process oracle gives the status as
"Inactive"?
Connection pooling works by keeping connections "established" behind
the scenes so you're going to see these Inactive sessions in v$session
but they're normal. This is the whole point of connection pooling since
it eliminates the overhead of establishing a new connection every time
you make a database call. You're also going to see at least 4 if each
of the apps has been hit at least once (since each app runs in a
separate process and connection pools are per process) but you're going
to see much more under normal use.

The connection pool mechanism in a nutshell:

1.) MyApp calls the Connection.Open().

2.) The library checks to see if there is an established but idle (not
in use by another thread in this same app) connection in the pool with
the exact same connection string and is not older than the time span
specified in the Connection Lifetime parameter of the connection string
(This is 0 by default, meaning maximum connection lifetime). If so, it
returns this connection, otherwise it establishes a new one.

3.) After you call connection.Close() the connection is still in the
pool and remains established, available for the next call to
Connection.Open()

Dec 14 '06 #8
<wf****@gmail.comwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
>Er, when they're inactive i.e. not being used for anything... Each
connection pool has a minimum number of connections which are created
when
the pool is first created.

Really?
Yes really.
I have never seen this before
Nevertheless...
You're also going to see at least 4 if each of the apps has been hit at
least once
Only if each pool has a minimum pool size of 1 - almost unheard of...
Dec 14 '06 #9

Mark Rae wrote:
You're also going to see at least 4 if each of the apps has been hit at
least once

Only if each pool has a minimum pool size of 1 - almost unheard of...
I believe the default (min pool size = 0) will create no additional
connections.

Dec 14 '06 #10
<wf****@gmail.comwrote in message
news:11**********************@80g2000cwy.googlegro ups.com...
Mark Rae wrote:
You're also going to see at least 4 if each of the apps has been hit at
least once

Only if each pool has a minimum pool size of 1 - almost unheard of...

I believe the default (min pool size = 0) will create no additional
connections.
That's true, but why would anyone do that...?
Dec 14 '06 #11

Mark Rae wrote:
<wf****@gmail.comwrote in message
news:11**********************@80g2000cwy.googlegro ups.com...
Mark Rae wrote:
You're also going to see at least 4 if each of the apps has been hit at
least once

Only if each pool has a minimum pool size of 1 - almost unheard of...
I believe the default (min pool size = 0) will create no additional
connections.

That's true, but why would anyone do that...?
I would ask the opposite. What good is this number unless your
application has a constant number of connections (how often is this
the case)?

Dec 14 '06 #12
<wf****@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
>Only if each pool has a minimum pool size of 1 - almost unheard of...

I believe the default (min pool size = 0) will create no additional
connections.

That's true, but why would anyone do that...?

I would ask the opposite. What good is this number unless your
application has a constant number of connections (how often is this
the case)?
The whole point of connection pooling is the idea that incoming database
requests *don't* have to be delayed waiting for a new connection to be
created, because there's already one waiting in the pool to be used...
Dec 14 '06 #13

Mark Rae wrote:
<wf****@gmail.comwrote in message
news:11**********************@f1g2000cwa.googlegro ups.com...
Only if each pool has a minimum pool size of 1 - almost unheard of...

I believe the default (min pool size = 0) will create no additional
connections.

That's true, but why would anyone do that...?
I would ask the opposite. What good is this number unless your
application has a constant number of connections (how often is this
the case)?

The whole point of connection pooling is the idea that incoming database
requests *don't* have to be delayed waiting for a new connection to be
created, because there's already one waiting in the pool to be used...
This won't change in either scenario, the connections have to be opened
at some point. My point is that letting the application dynamically
determine the minimum size of the pool based on the usage (usually this
will vary depending on the timeframe) is ideal in many if not most
situations. Otherwise you are just introducing the overhead of
maintaining a minimum amount of connections.

Dec 15 '06 #14

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

Similar topics

3
2777
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
2397
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
4156
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
2559
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
2116
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
8412
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
6051
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
13666
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...
5
3366
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
7218
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
7103
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
7307
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
5614
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,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.