Invalid attempt to Read when reader is closed.

A

Andy Green

Ok, here's a really strange one... let's see if anyone else has seen this or
if they have a fix for it.

I have some VB.NET code on an ASP.NET application... it opens a datareader,
then calls a function (passing the datareader as a parameter) to assign the
values to the objects properties.

Every once in a while, right in the middle of the Assign function (which is
just basically a bunch of

_variable = dr("sqlparam")

It will give me this error message:

Invalid attempt to Read when reader is closed.

I can hit refresh in the browser and it works fine. Then every once in a
while it'll happen again.

Now, he's the worst part - it ONLY HAPPENS when the app was built in
"Release" mode - it doesn't happen when it's built in "Debug" mode.

Any takers on this one?

Andy, (e-mail address removed)
 
W

William \(Bill\) Vaughn

It sounds like the DataReader's connection is getting closed and that can
cause the DataReader to close. Are you using a global connection object?

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
A

Andy Green

It's global, but only to the object. The connection never gets closed
manually... I mean, all this stuff happens right in the middle of
operations...

And why would it only happen when compiled under Release mode and not when
built under Debug mode?
 
W

William \(Bill\) Vaughn

I expect that the difference is a "race" condition where the production
version does not have to execute a lot of debug code.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
A

Andy Green

Hmmm... why would it work, then, just be refreshing the page? Again, we're
talking about just a bunch of assignments to local variables from the data
reader...

Andy, (e-mail address removed)
 
W

William \(Bill\) Vaughn

The DataReader is not serializeable and is not persistable in the Session or
ViewState.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
MVP, hRD
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top