473,725 Members | 2,251 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Understanding Connection Pooling

viswarajan
10 New Member
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?

Connection pooling is the ability of re-use your connection to the Database. This means if you enable Connection pooling in the connection object, actually you enable the re-use of the connection to more than one user.

The connection pooling is enabled by default in the connection object. If you disable the connection pooling, this means the connection object which you create will not be re-used to any other user than who create that object.

Shall I Enable/Disable Connection pool?

Let's do an example to use what the time has required if we enable/disable the connection pool in an application.

Sample 1(Connection Pooling is enabled):

Create a console application and put the following lines of code to Main Method:
Expand|Select|Wrap|Line Numbers
  1. SqlConnection testConnection =  new SqlConnection(@"Data Source=(local)\SQLEXPRESS;Initial Catalog=DEMO;Integrated Security=SSPI;");
  2.  
  3. long startTicks = DateTime.Now.Ticks;
  4.  
  5. for (int i = 1; i <= 100; i++)
  6.  
  7. {
  8.  
  9.     testConnection.Open();
  10.  
  11.     testConnection.Close();
  12.  
  13. }
  14.  
  15. long endTicks = DateTime.Now.Ticks;
  16.  
  17. Console.WriteLine("Time taken : " + (endTicks - startTicks) + " ticks.");
  18.  
  19. testConnection.Dispose();
  20.  
]

Run the application, on my machine the difference in time is: 937626 ticks

Sample 2(Connection Pooling is disabled):

Just add Pooling=false in the connection string.

Run the application, on my machine the difference in time is: 3906500 ticks

If you measure the difference you will see the time required by disabling the connection polling is 4 times greater than using connection pooling.

On of the good practices when using your connection object is enclose your code by try {..} catch {} finally {} blocks.

On finally block you have to call Conn.Close(); or Conn.Dispose();

To remove all resources attached to that connection.

One of you asked what's the difference of calling Close or Dispose, the answer don't use both of them, Dispose method actually call close method internally plus remove all allocated resource for that object to be garbage collected and at the same time the underlying connection object can be pooled.

Conclusion

Use connection pooling in your applications to maximize the use of physical connection with the Database and your application.

Thanks,
Natarajan.V
<link removed>
Aug 20 '07 #1
0 6611

Sign in to post your reply or Sign up for a free account.

Similar topics

18
3244
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
5725
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
2206
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
10294
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
2339
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
2867
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
3288
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 ? ...
15
3285
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
2
1925
by: Tony Johansson | last post by:
Hello! How does this connection pool function actually ? As I have been told is that when the connection is returned to the pool the connection to the database is still open. What you do is that you just return a still open connection to the pool. When I open a connection I get an already open connection to the database. Is this correct understood ?
0
8889
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
8752
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,...
1
9179
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8099
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...
0
6011
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
4519
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3228
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2637
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
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.