Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Passing around open readers

Reply
Thread Tools

Passing around open readers

 
 
blue
Guest
Posts: n/a
 
      01-23-2004
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


 
Reply With Quote
 
 
 
 
=?Utf-8?B?VHUtVGhhY2g=?=
Guest
Posts: n/a
 
      01-23-2004
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



 
Reply With Quote
 
 
 
 
Sharon
Guest
Posts: n/a
 
      03-06-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      03-06-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>




 
Reply With Quote
 
Teemu Keiski
Guest
Posts: n/a
 
      03-06-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>
>





 
Reply With Quote
 
Sharon
Guest
Posts: n/a
 
      03-06-2004
Thanks for the important correction.

"Teemu Keiski" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> 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" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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
> >
> >

>
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
WTB: I BUY SOFTWARE - CHECK AROUND - YOU PROBABLY HAVE SOME OF THEBELOW LAYING AROUND. Network/Software Buyer C++ 0 05-23-2010 07:14 PM
Do DNG readers age like RAW readers/converters?? Davy Digital Photography 1 09-29-2007 07:43 PM
Microsoft & patents: what goes around comes around... Lawrence D'Oliveiro NZ Computing 104 12-16-2006 07:11 AM
Read all of this to understand how it works. then check around on otherRead all of this to understand how it works. then check around on other thelisa martin Computer Support 2 08-18-2005 06:40 AM
Make wxListCtrl fit around contents and parent frame fit around listctrl Piet Python 0 07-18-2004 08:27 AM



Advertisments