473,471 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Sqlclient - connection pooling

Hi,

I'am working on an asp.net web project. was looking at some sources and
as i can see ppl creates new "sqlconnection" instances for each query
(or for every module). I know there's a pooling mechanism but isn't it
better to have a connection created at "page_load" and closed when
request handling completes?
Shall i create a new connection for every single module or create just
one for every page request?

Thanks.

Jan 18 '06 #1
3 1432
Antimon,

You should create your connection when you need it, and dispose of it
when you are done with your operation, no more, no less.

In an ASP.NET application, I can't see why you would need to maintain an
open connection beyond the processing of your page (in other words, on the
class level, and not disposing of it).

My recommendation would be to have a static method which will create
your connection for you, unopened (it will set up the connection string, so
you can change the details of your connection everywhere when needed later
on). You can store this on the page level, getting it on the Load event of
the page.

You would have to make sure that you close it in the Unload event on
your page as well.

This way, you can share the database connection throughout the methods
on your page. If you want your classes to use the same database connection,
you will have to pass it to them somehow.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Antimon" <an*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Hi,

I'am working on an asp.net web project. was looking at some sources and
as i can see ppl creates new "sqlconnection" instances for each query
(or for every module). I know there's a pooling mechanism but isn't it
better to have a connection created at "page_load" and closed when
request handling completes?
Shall i create a new connection for every single module or create just
one for every page request?

Thanks.

Jan 19 '06 #2
Thanks for the response Nicholas,

I can manage to have a database connection opened till the page render
ends but i'M not sure if it is the best way. I mean, every single page
in my project will do a session validation on database, check for any
incoming messages to user, and do some other stuff with database. In
some open source projects, it creates a conn and validates session
data, disposes it. creates a new one (in another method ofcourse),
checks for any incoming messages and disposes it. creates a new one for
the main reason of that page, uses that conn and disposes. These all
could have done in just one connection with your approach.

But i thought there might be an advantage on creating a connection for
the minimal time possible even if it means creating 2 more connections
for the same page... Is it?

Jan 19 '06 #3
Antimon,

Well, it's a matter of scope. You ^know^ that processing isn't going to
go beyond your page, so as a (possibly slight) optmization, you can
establish that the connection is obtained from "somewhere" (that somewhere
being your page) and then use that.

This is one option. Another option would be to use connection pooling.
Assuming that it is one user that is accessing the database, connection
pooling can be a big boon and allow you to compartmentalize your design
(assuming that you get your connections from the same source).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Antimon" <an*****@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Thanks for the response Nicholas,

I can manage to have a database connection opened till the page render
ends but i'M not sure if it is the best way. I mean, every single page
in my project will do a session validation on database, check for any
incoming messages to user, and do some other stuff with database. In
some open source projects, it creates a conn and validates session
data, disposes it. creates a new one (in another method ofcourse),
checks for any incoming messages and disposes it. creates a new one for
the main reason of that page, uses that conn and disposes. These all
could have done in just one connection with your approach.

But i thought there might be an advantage on creating a connection for
the minimal time possible even if it means creating 2 more connections
for the same page... Is it?

Jan 19 '06 #4

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

Similar topics

18
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...
1
by: ugurceng | last post by:
Hi everbody , I need more info about connection pooling , We are developing a CRM project with ASP.NET and when more users connect to the MS SQL DB at the same time , which problems would be...
1
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...
0
by: cristo | last post by:
I, After reading all what I could find I have some question about transaction and connection pooling. Let`s look at an example : Dim _transOpt As TransactionOptions...
2
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...
3
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...
9
by: fniles | last post by:
I am using VB.NET 2003 and SQL 2005. To use connection pooling and avoid the error "There is already an open DataReader associated with this Connection which must be closed first." , I understand...
0
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...
1
by: fniles | last post by:
I am using VB.NET 2005 and SQL Server. I would like to test how many connections I can have open in the connection pooling. 1. In the connection string if I do not include "Max Pool Size=200",...
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
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,...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.