473,507 Members | 3,706 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing around open readers

We often get connection pooling errors saying that there are no available
connections in the pool.

I think the problem is that we are passing around open readers all over the
place. I am planning on changing this in our code and I expect this to fix
our problem.

We have our connection pooling set to the default number of connections
open. We probably have about 3-7 users concurrently using our web site.
So, the problem isn't that we have too many users.

If passing open readers to methods is causing our problem, my question is
why? Is it making a copy of the reader when it gets passed around and the
copy isn't getting closed?

We are doing this:

public void method1()
{
SqlDataReader reader = SqlHelper.ExecuteReader(...);

method2(reader);

reader.Close();
}

We are closing the reader on the calling side but I suspect that a new copy
of the open reader is staying open in the called method.

What do you think? Am I on the right track?

Thanks,

blue
Nov 18 '05 #1
5 1638
blue,
Did you close the SqlConnection object as well?
Tu-Thach

----- blue wrote: -----

We often get connection pooling errors saying that there are no available
connections in the pool.

I think the problem is that we are passing around open readers all over the
place. I am planning on changing this in our code and I expect this to fix
our problem.

We have our connection pooling set to the default number of connections
open. We probably have about 3-7 users concurrently using our web site.
So, the problem isn't that we have too many users.

If passing open readers to methods is causing our problem, my question is
why? Is it making a copy of the reader when it gets passed around and the
copy isn't getting closed?

We are doing this:

public void method1()
{
SqlDataReader reader = SqlHelper.ExecuteReader(...);

method2(reader);

reader.Close();
}

We are closing the reader on the calling side but I suspect that a new copy
of the open reader is staying open in the called method.

What do you think? Am I on the right track?

Thanks,

blue

Nov 18 '05 #2
In C# the default for mathod parameter is "by value".
This means that the reader is copyed and holds the connection open.
To pass the parameter "by reference" add ref to the method definition:
public void method2(ref SqlDataReader dr)
Hope this helps.
Sharon.

"blue" <bl**@arizona.edu> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
We often get connection pooling errors saying that there are no available
connections in the pool.

I think the problem is that we are passing around open readers all over the place. I am planning on changing this in our code and I expect this to fix our problem.

We have our connection pooling set to the default number of connections
open. We probably have about 3-7 users concurrently using our web site.
So, the problem isn't that we have too many users.

If passing open readers to methods is causing our problem, my question is
why? Is it making a copy of the reader when it gets passed around and the
copy isn't getting closed?

We are doing this:

public void method1()
{
SqlDataReader reader = SqlHelper.ExecuteReader(...);

method2(reader);

reader.Close();
}

We are closing the reader on the calling side but I suspect that a new copy of the open reader is staying open in the called method.

What do you think? Am I on the right track?

Thanks,

blue

Nov 18 '05 #3
Hi,

Reference types (which SqlDataReader is) passed as parameter are always
passing a copy of reference to the method, despite do you have ref keyword
or not With reference type the ultimate result is the same if you call
methods or change properties, though ref keyword has impact on if you can
reassign the original reference (without ref keyword you can impact on the
object by accessing members but you can't reassign the reference e.g it has
no effect outside the method, with ref keyword, you can do that too).

In this case it means that the SqlDataReader object is *not* copied but the
reference to it is. When accessing the copied reference, the copy is
indistinguishable from the original reference. So if you call Close on
another reference, it is closed for all references (as it is one and the
same underlying object). So it shouldn't be the reason here.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Sharon" <ta*******@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
In C# the default for mathod parameter is "by value".
This means that the reader is copyed and holds the connection open.
To pass the parameter "by reference" add ref to the method definition:
public void method2(ref SqlDataReader dr)
Hope this helps.
Sharon.

"blue" <bl**@arizona.edu> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
We often get connection pooling errors saying that there are no available
connections in the pool.

I think the problem is that we are passing around open readers all over the place. I am planning on changing this in our code and I expect this to fix our problem.

We have our connection pooling set to the default number of connections
open. We probably have about 3-7 users concurrently using our web site.
So, the problem isn't that we have too many users.

If passing open readers to methods is causing our problem, my question is
why? Is it making a copy of the reader when it gets passed around and the
copy isn't getting closed?

We are doing this:

public void method1()
{
SqlDataReader reader = SqlHelper.ExecuteReader(...);

method2(reader);

reader.Close();
}

We are closing the reader on the calling side but I suspect that a new copy of the open reader is staying open in the called method.

What do you think? Am I on the right track?

Thanks,

blue


Nov 18 '05 #4
Just to add, that I still wouldn't pass DataReaders through methods just
like that, because it might make things more complicated from error handling
standpoint (reader and db connection must be closed in error situations as
well). Therefore at least try...catch...finally block would be good when
passing the DataReader to the method and make sure that Close is called in
finally.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist
"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
Hi,

Reference types (which SqlDataReader is) passed as parameter are always
passing a copy of reference to the method, despite do you have ref keyword
or not With reference type the ultimate result is the same if you call
methods or change properties, though ref keyword has impact on if you can
reassign the original reference (without ref keyword you can impact on the
object by accessing members but you can't reassign the reference e.g it has
no effect outside the method, with ref keyword, you can do that too).

In this case it means that the SqlDataReader object is *not* copied but the
reference to it is. When accessing the copied reference, the copy is
indistinguishable from the original reference. So if you call Close on
another reference, it is closed for all references (as it is one and the
same underlying object). So it shouldn't be the reason here.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Sharon" <ta*******@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
In C# the default for mathod parameter is "by value".
This means that the reader is copyed and holds the connection open.
To pass the parameter "by reference" add ref to the method definition:
public void method2(ref SqlDataReader dr)
Hope this helps.
Sharon.

"blue" <bl**@arizona.edu> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
We often get connection pooling errors saying that there are no available
connections in the pool.

I think the problem is that we are passing around open readers all over the place. I am planning on changing this in our code and I expect this to fix our problem.

We have our connection pooling set to the default number of connections
open. We probably have about 3-7 users concurrently using our web site.
So, the problem isn't that we have too many users.

If passing open readers to methods is causing our problem, my question is
why? Is it making a copy of the reader when it gets passed around and the
copy isn't getting closed?

We are doing this:

public void method1()
{
SqlDataReader reader = SqlHelper.ExecuteReader(...);

method2(reader);

reader.Close();
}

We are closing the reader on the calling side but I suspect that a new copy of the open reader is staying open in the called method.

What do you think? Am I on the right track?

Thanks,

blue



Nov 18 '05 #5
Thanks for the important correction.

"Teemu Keiski" <jo****@aspalliance.com> wrote in message
news:uf**************@TK2MSFTNGP12.phx.gbl...
Hi,

Reference types (which SqlDataReader is) passed as parameter are always
passing a copy of reference to the method, despite do you have ref keyword
or not With reference type the ultimate result is the same if you call
methods or change properties, though ref keyword has impact on if you can
reassign the original reference (without ref keyword you can impact on the
object by accessing members but you can't reassign the reference e.g it has no effect outside the method, with ref keyword, you can do that too).

In this case it means that the SqlDataReader object is *not* copied but the reference to it is. When accessing the copied reference, the copy is
indistinguishable from the original reference. So if you call Close on
another reference, it is closed for all references (as it is one and the
same underlying object). So it shouldn't be the reason here.

--
Teemu Keiski
MCP, Microsoft MVP (ASP.NET), AspInsiders member
ASP.NET Forum Moderator, AspAlliance Columnist

"Sharon" <ta*******@hotmail.com> wrote in message
news:Ov**************@TK2MSFTNGP10.phx.gbl...
In C# the default for mathod parameter is "by value".
This means that the reader is copyed and holds the connection open.
To pass the parameter "by reference" add ref to the method definition:
public void method2(ref SqlDataReader dr)
Hope this helps.
Sharon.

"blue" <bl**@arizona.edu> wrote in message
news:uE**************@TK2MSFTNGP12.phx.gbl...
We often get connection pooling errors saying that there are no available connections in the pool.

I think the problem is that we are passing around open readers all over

the
place. I am planning on changing this in our code and I expect this to

fix
our problem.

We have our connection pooling set to the default number of connections
open. We probably have about 3-7 users concurrently using our web site.
So, the problem isn't that we have too many users.

If passing open readers to methods is causing our problem, my question is why? Is it making a copy of the reader when it gets passed around and the copy isn't getting closed?

We are doing this:

public void method1()
{
SqlDataReader reader = SqlHelper.ExecuteReader(...);

method2(reader);

reader.Close();
}

We are closing the reader on the calling side but I suspect that a new

copy
of the open reader is staying open in the called method.

What do you think? Am I on the right track?

Thanks,

blue


Nov 18 '05 #6

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

Similar topics

1
2539
by: IS | last post by:
Hi folks, Any ideas why this doesn't work? <SCRIPT LANGUAGE="JavaScript"> <!-- f = document.forms; e = f.elements; str = new String(e.value); len = document.forms.d.options.length;
27
6163
by: Oscar | last post by:
I am looking for a way to pass an ADO recordset that has been retrieved in an ASP page to another HTML-page. Is there someone who can provide me with a small sample or a link to see how this is...
3
4738
by: Simon Harvey | last post by:
Hi, In my application I get lots of different sorts of information from databases. As such, a lot of information is stored in DataSets and DataTable objects. Up until now, I have been passing...
8
2106
by: Dennis Myrén | last post by:
I have these tiny classes, implementing an interface through which their method Render ( CosWriter writer ) ; is called. Given a specific context, there are potentially a lot of such objects,...
22
25548
by: Arne | last post by:
How do I pass a dataset to a webservices? I need to submit a shoppingcart from a pocket PC to a webservice. What is the right datatype? II have tried dataset as a datatype, but I can't get it to...
1
299
by: thomasp | last post by:
In the code below I have a function that tests if a file exists. It takes a variable named strFileName, simple enough. My question is, is there a way to pass it a variable with another name as...
16
3431
by: akantrowitz | last post by:
In csharp, what is the correct locking around reading and writing into a hashtable. Note that the reader is not looping through the keys, simply reading an item out with a specific key: If i...
4
2085
by: shade73 | last post by:
Hey all. I currently have two seperate namespaces and I'm trying to pass a connection around to them. I want to use the same connection & leave it open for 6 methods & then close it. However, all...
20
5558
by: Author | last post by:
a .net 1.1 app has a class whose constructor opens a db connection to sql svr two thousand. this class has more than a dozen of methods. most of them don't do db stuff. I am wondering if this...
0
7109
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
7313
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
7372
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...
1
7029
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
7481
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...
1
5039
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
3190
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
3179
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
758
muto222
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.