473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

dbReader closing prematurely

I have a section of code that is giving me an error:
************************************************** ***************
Invalid attempt to Read when reader is closed.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Invalid attempt to Read
when reader is closed.

Source Error:
Line 1701: dbReader =
myDBObject.RunProcedure("GetScreenQuestions",param eters)
Line 1702:trace.warn("Before dbReader.Read")
Line 1703: while dbReader.Read() <-
error is here 2nd time around
Line 1704:trace.warn("inside dbRead.Read")
Line 1705: redim parameters(6)
************************************************** ***************************

My code is:
******************************************
Dim myDbObject as new DbObject()
Dim dbReader As SqlDataReader

....

dbReader = myDBObject.RunProcedure("GetScreenQuestions",param eters)
trace.warn("Before dbReader.Read")
while dbReader.Read()
trace.warn("inside dbRead.Read")
redim parameters(6)
parameters(0) = new
SqlParameter("@ScreenQuestionsTemplateID",SqlDBTyp e.Int)
parameters(1) = new SqlParameter("@Question",SqlDBType.VarChar,250)
parameters(2) = new SqlParameter("@QuestionType",SqlDBType.Char,2)
parameters(3) = new SqlParameter("@SortOrder",SqlDBType.SmallInt)
parameters(4) = new SqlParameter("@Answers",SqlDBType.SmallInt)
parameters(5) = new SqlParameter("@Weight",SqlDBType.SmallInt)
parameters(6) = new SqlParameter("@ScreenTemplateMasterID",SqlDBType.I nt)

parameters(0).Value = dbReader("ScreenQuestionsTemplateID")
parameters(1).Value = dbReader("Question")
parameters(2).Value = dbReader("QuestionType")
parameters(3).Value = dbReader("SortOrder")
parameters(4).Value = dbReader("Answers")
parameters(5).Value = dbReader("Weight")
parameters(6).Value = ScreenTemplateMasterID

Call myDbObject.RunProcedure("CopyScreenTemplateFromTem plate",parameters)
end while
*****************************************

RunProcedure is my own Database Object.

The first RunProcedure passes back a DataReader (dbReader) and it works fine
the first time through.

But apparently the call to RunProcedure is killing or closing dbReader. Why
would that be?

I am not reusing the DataReader, just using doing a Call.

Thanks,

Tom

Jan 11 '06 #1
2 1310
Tom,
A SqlDataReader is a forward-only "firehose" style data object. This means
you only get to read through it "One Time". After you are done with the
Reader, you need to Close it and optionally close the underlying
SqlConnection if you haven't specified CommandBehavior.CloseConnection.

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"tshad" wrote:
I have a section of code that is giving me an error:
************************************************** ***************
Invalid attempt to Read when reader is closed.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Invalid attempt to Read
when reader is closed.

Source Error:
Line 1701: dbReader =
myDBObject.RunProcedure("GetScreenQuestions",param eters)
Line 1702:trace.warn("Before dbReader.Read")
Line 1703: while dbReader.Read() <-
error is here 2nd time around
Line 1704:trace.warn("inside dbRead.Read")
Line 1705: redim parameters(6)
************************************************** ***************************

My code is:
******************************************
Dim myDbObject as new DbObject()
Dim dbReader As SqlDataReader

....

dbReader = myDBObject.RunProcedure("GetScreenQuestions",param eters)
trace.warn("Before dbReader.Read")
while dbReader.Read()
trace.warn("inside dbRead.Read")
redim parameters(6)
parameters(0) = new
SqlParameter("@ScreenQuestionsTemplateID",SqlDBTyp e.Int)
parameters(1) = new SqlParameter("@Question",SqlDBType.VarChar,250)
parameters(2) = new SqlParameter("@QuestionType",SqlDBType.Char,2)
parameters(3) = new SqlParameter("@SortOrder",SqlDBType.SmallInt)
parameters(4) = new SqlParameter("@Answers",SqlDBType.SmallInt)
parameters(5) = new SqlParameter("@Weight",SqlDBType.SmallInt)
parameters(6) = new SqlParameter("@ScreenTemplateMasterID",SqlDBType.I nt)

parameters(0).Value = dbReader("ScreenQuestionsTemplateID")
parameters(1).Value = dbReader("Question")
parameters(2).Value = dbReader("QuestionType")
parameters(3).Value = dbReader("SortOrder")
parameters(4).Value = dbReader("Answers")
parameters(5).Value = dbReader("Weight")
parameters(6).Value = ScreenTemplateMasterID

Call myDbObject.RunProcedure("CopyScreenTemplateFromTem plate",parameters)
end while
*****************************************

RunProcedure is my own Database Object.

The first RunProcedure passes back a DataReader (dbReader) and it works fine
the first time through.

But apparently the call to RunProcedure is killing or closing dbReader. Why
would that be?

I am not reusing the DataReader, just using doing a Call.

Thanks,

Tom

Jan 11 '06 #2

"Peter Bromberg [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:C6**********************************@microsof t.com...
Tom,
A SqlDataReader is a forward-only "firehose" style data object. This
means
you only get to read through it "One Time". After you are done with the
Reader, you need to Close it and optionally close the underlying
SqlConnection if you haven't specified CommandBehavior.CloseConnection.
That I understand.

But if I comment out the RunProcedure in the While loop, it goes through it
about 10 times (as there are 10 records).

If I don't, I get the error on the 2nd While statement (which is after the
RunProcedure was run for the first time). It appears to have closed the
dbReader before I have read through it.

Thanks,

Tom
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"tshad" wrote:
I have a section of code that is giving me an error:
************************************************** ***************
Invalid attempt to Read when reader is closed.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: Invalid attempt to
Read
when reader is closed.

Source Error:
Line 1701: dbReader =
myDBObject.RunProcedure("GetScreenQuestions",param eters)
Line 1702:trace.warn("Before dbReader.Read")
Line 1703: while dbReader.Read() <-
error is here 2nd time around
Line 1704:trace.warn("inside dbRead.Read")
Line 1705: redim parameters(6)
************************************************** ***************************

My code is:
******************************************
Dim myDbObject as new DbObject()
Dim dbReader As SqlDataReader

....

dbReader = myDBObject.RunProcedure("GetScreenQuestions",param eters)
trace.warn("Before dbReader.Read")
while dbReader.Read()
trace.warn("inside dbRead.Read")
redim parameters(6)
parameters(0) = new
SqlParameter("@ScreenQuestionsTemplateID",SqlDBTyp e.Int)
parameters(1) = new SqlParameter("@Question",SqlDBType.VarChar,250)
parameters(2) = new SqlParameter("@QuestionType",SqlDBType.Char,2)
parameters(3) = new SqlParameter("@SortOrder",SqlDBType.SmallInt)
parameters(4) = new SqlParameter("@Answers",SqlDBType.SmallInt)
parameters(5) = new SqlParameter("@Weight",SqlDBType.SmallInt)
parameters(6) = new
SqlParameter("@ScreenTemplateMasterID",SqlDBType.I nt)

parameters(0).Value = dbReader("ScreenQuestionsTemplateID")
parameters(1).Value = dbReader("Question")
parameters(2).Value = dbReader("QuestionType")
parameters(3).Value = dbReader("SortOrder")
parameters(4).Value = dbReader("Answers")
parameters(5).Value = dbReader("Weight")
parameters(6).Value = ScreenTemplateMasterID

Call
myDbObject.RunProcedure("CopyScreenTemplateFromTem plate",parameters)
end while
*****************************************

RunProcedure is my own Database Object.

The first RunProcedure passes back a DataReader (dbReader) and it works
fine
the first time through.

But apparently the call to RunProcedure is killing or closing dbReader.
Why
would that be?

I am not reusing the DataReader, just using doing a Call.

Thanks,

Tom

Jan 11 '06 #3

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

Similar topics

2
by: Jazzis | last post by:
After moving my application from W2K / IIS5 to W2K3 / II6 the application works pefrectly BUT the user session expire prematurely (after about 2 mins) rendering the application unusable. Help /...
0
by: Neil Zanella | last post by:
Hello, I would like to know whether it is possible to return prematurely from the body of a MySQL 5 procedure. It seems MySQL 5 only allows the RETURN keyword in PROCEDURES, so I end up having...
10
by: Tom Szabo | last post by:
Is there an event when that triggers when the window is closing.... I am talking about when the user clicks on the cross on the right top corner of the window!!!
3
by: microsoft.news.com | last post by:
How can I this but using the dbReader instead of the streamreader and get all the items instead of the last one in my text file i'm populating? this works fine: StreamReader sr = new...
4
by: tshad | last post by:
I have a function that is getting an error on my dbReader statment: C:\VSProjects\ClassLibrary4\NewHire.cs(53): 'dbReader' denotes a 'variable' where a 'method' was expected Here is the...
5
by: rdemyan via AccessMonster.com | last post by:
I'm getting the following error message both when opening and closing my dB. The Microsoft Jet database engine cannot find the input table or query 'MSysAccessStorage'. Make sure it exists and...
3
by: Brainsludge | last post by:
Hello, I am running WinXP SP2 with Python 2.5.1 and encountered the following issue: I wrote a script that logs into my mail server, and checks for new messages every 20 seconds. When a new...
19
by: rbrowning1958 | last post by:
Hello, I am confused by dispose etc. and hope someone can set me right. 1. The Dispose(Bool) the IDE generates for a form has nothing to do with IDisposable, right? 2. So when is this called?...
0
by: lpizzle | last post by:
I am embedding a SQL editor in my company's existing program to allow our clients to easily run queries against our database. The current layout is a textbox where they type in the code and a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
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
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
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,...

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.