473,626 Members | 3,439 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Connection pooling

As I understand it, if I create a connection object in my application
and close the connection, the next time I open a connection with the
same connection string I should be using a pooled connection?

Is this possible over different instances of a class.

For example

Instance 1 of my dll is alive and creates a connection to a Database.
The class goes out of scope (I have closed the connection by this stage)
and instance 2 is now alive and I create a conneciton using the same Db
string.

Can I use a pooled connection in this scenario.

I ask this ebcause its taking me around 140ms to create a connection to
a sql2005 each time I receive a message from another application.
However, we have some visual basic code which is doing the same thing
which takes 200ms for first connection, but sebsequent connections <1ms
(A new instance of the VB dll is created for each message).

Steven

*** Sent via Developersdex http://www.developersdex.com ***
May 14 '06 #1
10 3157
Pooled Connections are managed by the Framework, not by individual
assemblies. So, what assembly opens a Connection is irrelevant. They all
work with the same pool.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be

"Steven Blair" <st**********@b tinternet.com> wrote in message
news:O3******** ********@TK2MSF TNGP05.phx.gbl. ..
As I understand it, if I create a connection object in my application
and close the connection, the next time I open a connection with the
same connection string I should be using a pooled connection?

Is this possible over different instances of a class.

For example

Instance 1 of my dll is alive and creates a connection to a Database.
The class goes out of scope (I have closed the connection by this stage)
and instance 2 is now alive and I create a conneciton using the same Db
string.

Can I use a pooled connection in this scenario.

I ask this ebcause its taking me around 140ms to create a connection to
a sql2005 each time I receive a message from another application.
However, we have some visual basic code which is doing the same thing
which takes 200ms for first connection, but sebsequent connections <1ms
(A new instance of the VB dll is created for each message).

Steven

*** Sent via Developersdex http://www.developersdex.com ***

May 14 '06 #2
I am not so sure about that.

I have been doing some tests today.

If I run my app once which opens a connection to a Sql2005 Db it takes
rouhgly 120ms. If I rerun the app, it takes 120ms again. Therefore I
would say its safe to say connection pooling isnt being used.
If I create a dll that opens a connection and call it from a console app
(create 2 instances of the dll in the console app) my first conenction
is 120ms and my 2nd is <1ms.

It seems the pooling works on an application level.

What do you think?
*** Sent via Developersdex http://www.developersdex.com ***
May 14 '06 #3

"Steven Blair" <st**********@b tinternet.com> wrote in message
news:O3******** ********@TK2MSF TNGP05.phx.gbl. ..
| As I understand it, if I create a connection object in my application
| and close the connection, the next time I open a connection with the
| same connection string I should be using a pooled connection?
|
| Is this possible over different instances of a class.
|
| For example
|
| Instance 1 of my dll is alive and creates a connection to a Database.
| The class goes out of scope (I have closed the connection by this stage)
| and instance 2 is now alive and I create a conneciton using the same Db
| string.
|
| Can I use a pooled connection in this scenario.
|
| I ask this ebcause its taking me around 140ms to create a connection to
| a sql2005 each time I receive a message from another application.
| However, we have some visual basic code which is doing the same thing
| which takes 200ms for first connection, but sebsequent connections <1ms
| (A new instance of the VB dll is created for each message).
|
| Steven
|
|
|
| *** Sent via Developersdex http://www.developersdex.com ***

Connection pooling is a complex beast, let me try to explain how Connection
pooling works.
Note that each provider may use different protocols and heuristics, here I'm
only talking about the SQL client provider.

Connection pools are per 'application domain' containers who are maintained
on a per db 'instance' per security context basis. That means that multiple
pools can exist in a process/application domain at the same time depending
on the instance and security context. Note also that two different AD's
cannot share the same pool.
A pool is established the first time you create a connection with a certain
instance using specific credentials. This is the most costly operation (say
150 msec's.) as it involves :

- the creation of the connection pool,
- an authentication handshake (a network logon) and,
- the establishment of a physical network connection.
When your application opens a subsequent connection with the same DB
instance using the same credentials, the provider will search the pool for a
free connection entry and return this one to your application. This is a
very cheap operation (a few hundred µsec's. or less) as it doesn't involve
any security handshake nor physical connection.

If no free entry exists in the pool, a new connection will be created with
the server, no authentication has to be done as long as a security context
exists between the client and the server, such contexts is maintained,by the
provider, per existing pool.

Now, when your application closes a connection, it's returned to the pool
where it waits (a reconnect time-out period) for a new open request from
your application to the same db instance using the same security context. If
no connection arrives before the 'reconnect time-out' expires, the
connection with the DB is closed and the entry removed from the pool. If
this entry was the last entry in the pool, the next connection request will
be more costly as the provider needs to establish a physical connection with
the db instance (can take >20 msec's. over TCP/IP), but it won't be as
costly as the first connection at pool creation time.

Now back to your findings, you seems to have measured the first connection
time, but you didn't tell us what kind of application you are talking about,
also you keep refereeing to DLL's and classes without specifying the
context. How are these assemblies loaded, are they AD loaded and unloaded,
what's the time interval between subsequent open calls?
Why don't you measure the effect of connection pooling by running a simple
console application?

Willy.



May 14 '06 #4
Thanks for the indepth reply :)

I trieds using a simple app. After the first connection (rouhgly about
140ms) subsequent conenctions are <1ms.

My main application however involves a new dll being created each time
my application receives a message:

Message 1 arrives, new dll is created, and therefore a connection is
created. I dont some processing and the conenction is then closed.
2nd message is received and a new instance of the dll is created and
same again, a new connection is created.

It does appear that this 2nd connection uses a pooled connection since
the time is <1ms.

The conenction strings do not change, so this is why I assumed the
pooling works on an application basis, ie, my exe is the driver program
which kicks off x amount of dll instances.
*** Sent via Developersdex http://www.developersdex.com ***
May 14 '06 #5
Here is breif outline of the full app:

A multi threaded TCP service (writting in C++) receives a number of
messages. Each message spawns a new instance of a C# dll via COM.
I have only tested the dll's being created via a Console app, but I
suspect (and a little hope) that it works the same. My first instance of
the C# dll will create the pool for this app, and subsequent dll's can
use that pool.

*** Sent via Developersdex http://www.developersdex.com ***
May 14 '06 #6

"Steven Blair" <st**********@b tinternet.com> wrote in message
news:u2******** ******@TK2MSFTN GP03.phx.gbl...
| Thanks for the indepth reply :)
|
| I trieds using a simple app. After the first connection (rouhgly about
| 140ms) subsequent conenctions are <1ms.
|
| My main application however involves a new dll being created each time
| my application receives a message:
|
| Message 1 arrives, new dll is created, and therefore a connection is
| created. I dont some processing and the conenction is then closed.
| 2nd message is received and a new instance of the dll is created and
| same again, a new connection is created.
|
You don't create instances of DLL's, what exactly do you mean by this?

| It does appear that this 2nd connection uses a pooled connection since
| the time is <1ms.
|

This proves that connection pooling is used, right?

| The conenction strings do not change, so this is why I assumed the
| pooling works on an application basis, ie, my exe is the driver program
| which kicks off x amount of dll instances.
|

You don't kick off dll instances, so you must mean something else.

Willy.
May 14 '06 #7
When a thread gets created on my TCp service, I create a new instance of
a c# dll, thats what I meant when I said "kick off".

I create an instance of my class within the dll:

Just to be clear, incase its my terminogloy:

MyDll d = new MyDll(); //for each TCP thread. I refer to this as
creating a new instance of my dll, but its a new instance of the class
inside :)

*** Sent via Developersdex http://www.developersdex.com ***
May 14 '06 #8

"Steven Blair" <st**********@b tinternet.com> wrote in message
news:ub******** ******@TK2MSFTN GP03.phx.gbl...
| Here is breif outline of the full app:
|
| A multi threaded TCP service (writting in C++) receives a number of
| messages. Each message spawns a new instance of a C# dll via COM.
| I have only tested the dll's being created via a Console app, but I
| suspect (and a little hope) that it works the same. My first instance of
| the C# dll will create the pool for this app, and subsequent dll's can
| use that pool.
|
Again, you don't create instances of C# DLL's, you can only create instances
of classes.
Here is what I think you are doing, a COM client (the C++ application) loads
the DLL and creates instance(s) of a class contained in the DLL. Each
message that arrives creates a new instance of a class, that instance
creates a db connection and starts a transaction, at the end of the
transaction, you close the connection.
Now, as I told you before, a pool is maintained per process (more precisely
per application domain) and has nothing to do with loading of DLL's. As long
as your application connects to the same db instance using the same
credentials, your process (application) uses the one and only pool. If
however, you change the credentials per connection, you will create a new
pool and you will incur the initial overhead for each new connection.
Now I would like to get some more questions answered;
1. What version of the framework are you running I assume v2.
2. Does your service create a thread per incoming message and do you create
an instance of the C# class in this thread?
3. How does your connection string looks like, here I mean, do you use
integrated security or sql security using explict credentials.
4. What's the interval between incoming TCP messages and what's the service
time of a transaction (duration of the connection).

Willy.

May 14 '06 #9
Ok, thank you for the reply.

To answer your questions:

1. V.20
2. Yes
3. I am using Windows authentication:

Data Source=TS3DB04; Initial Catalog=VS_Acco unt;Integrated
Security=True

4. We could be receiving multiple transactions per second. At least 20
messages per second. Its heavy processing, so thats why I need message
processing times down to minimum.
At the moment, using the leagcy software, message times are somewhere
between 30-80ms for the round trip. However, this is using Sql2000. The
software I am developing should be processing roughly the same time if
possible. There does seem to be a longer time penelty for connecting to
Sql 2005 initially.

Thanks for the continued support.

Steven


*** Sent via Developersdex http://www.developersdex.com ***
May 15 '06 #10

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

Similar topics

18
3225
by: Rob Nicholson | last post by:
We're getting an occasional occurrence of the following error when two users try and open the same record in our ASP.NET app: "There is already an open DataReader associated with this Connection which must be closed first." As suggested, I was closing the connection in the Finally part of the outer Try but I wasn't closing the data reader as well so I assume that if the following happens, the above error could occur
1
5718
by: Lenny Shprekher | last post by:
Hi, I am getting issues that Oracle collecting opened sessions (connections) from my webservice using regular System.Data.OleDb.OleDbConnection object. I am guessing that this is connection pooling issue. Is there is any way to disable connection pooling for one particular .net webservice? Thanks, Leonid
7
2201
by: Mrinal Kamboj | last post by:
Hi , I am using OracleConnection object from Oracle ODP.net provider and following is the behaviour which i am finding bit strange : To start with my argument is based on followings facts : 1. Connection object is a reference type object . 2. All reference types are passed by reference even when done without using modifier like ref / out .
3
10287
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database I use System.Data.Common.DBConnection and .DBCommand. How can I keep aware from connection losses (network not availeable, db-server not available...)? Are there any strategies to detect this broken connections, and how can I
2
2332
by: JimLad | last post by:
Hi, In an existing ASP/ASP.NET 1.1 app running on IIS 6, I need to RELIABLY pass the logged in username through to the SQL Server 2000 database for auditing purposes. The current method is hideously unreliable. The app includes updategrams, XML Templates and ADO connections. I don't want to use impersonation because of the direct db access that allows.
16
2862
by: crbd98 | last post by:
Hello All, Some time ago, I implemented a data access layer that included a simple connectin pool. At the time, I did it all by myself: I created N connections, each connection associated with a worker thread that would execute the db commands. The pool was fixed and all the connections were created when the db access class was instantiated. The connections remained opened during the whole execution. If a connection was not available...
20
3269
by: fniles | last post by:
I am using VS2003 and connecting to MS Access database. When using a connection pooling (every time I open the OLEDBCONNECTION I use the exact matching connection string), 1. how can I know how many connection has been used ? 2. If the maximum pool size has been reached, what happens when I call the method Open to open the connection ? Will I get an error ? MSDN says the request is queued, but will I get an error in the open method ? ...
3
4884
by: fniles | last post by:
In the Windows application (using VB.NET 2005) I use connection pooling like the following: In the main form load I open a connection using a connection string that I stored in a global variable g_sConnectionString and leave this connection open and not close it until it exits the application. Then on each thread/each subsequent sub that needs the connection I create a local OleDBConnection variable, open the connection using the exact...
0
6597
viswarajan
by: viswarajan | last post by:
Introduction This article is to go in deep in dome key features in the ADO.NET 2 which was shipped with VS 2005. In this article I will go trough one of the key features which is the Connection Pooling. This feature is a key feature plays an important role in the performance in most of business application or Data driven application. What's Connection Pooling?
15
3277
by: Sylvie | last post by:
I have a static function in a class, everytime I call this function, I am creating a SQLconnection, open it, use it, and null it, All my functions and application logic is like this, Every connection is creating self connection object and null it after the some process, Is this wrong ? One of my friend told me about "Connection Pooling", and I am confused
0
8268
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8202
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8707
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8510
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7199
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6125
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5575
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4202
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1512
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.