Wrox Home  
Search P2P Archive for: Go

  Return to Index  

ado_dotnet thread: Error!!! (Invalid attemp to read when reader is closed)


Message #1 by "Mustafa" <syedmustafashah@f...> on Wed, 23 Oct 2002 06:07:38
Hi All!!
I am using ADO .Net in a windows application in Vb.net. I have a function 
that accepts a query and return the results in a DataTable. It works fine 
for most of the time but some times it starts giving an error 
i.e "System.InvalidoperationException: Invalid attempt to read when the 
reader is closed"

I am not using the reader explicitely. I am using data Adapter and the 
error occures in "DA.Fill(DataTable)" call. 

I have searched for this error statement on the web and in MSDN but in 
vain. I hope someone can give me an idea of what should i try.

my code looks like this .....

                Me.objCmd = New System.Data.SqlClient.SqlCommand(strSql)
                Me.objCmd.Connection = objConnection
                Me.objDa = New System.Data.SqlClient.SqlDataAdapter(objCmd)
                Me.objDt = New System.Data.DataTable()
                Me.objDa.Fill(objDt)
                Return objDt

Well there is another observation that this error occures when this 
function is called in a loop for getting many results from different 
queries.

Hope to hear from you soon
Regards
Mustafa 
Message #2 by "Bernie Yaeger" <berniey@c...> on Wed, 23 Oct 2002 11:09:49 -0400
Hi Mustafa,

I tested your code and could not replicate the error, although I did have to
guess at where your code was loading and what the connection object and
strsql looked like.

Can you email me more info so that I can test it further?

Regards,

Bernie Yaeger

----- Original Message -----
From: "Mustafa" <syedmustafashah@f...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Wednesday, October 23, 2002 6:07 AM
Subject: [ado_dotnet] Error!!! (Invalid attemp to read when reader is
closed)


> Hi All!!
> I am using ADO .Net in a windows application in Vb.net. I have a function
> that accepts a query and return the results in a DataTable. It works fine
> for most of the time but some times it starts giving an error
> i.e "System.InvalidoperationException: Invalid attempt to read when the
> reader is closed"
>
> I am not using the reader explicitely. I am using data Adapter and the
> error occures in "DA.Fill(DataTable)" call.
>
> I have searched for this error statement on the web and in MSDN but in
> vain. I hope someone can give me an idea of what should i try.
>
> my code looks like this .....
>
>                 Me.objCmd = New System.Data.SqlClient.SqlCommand(strSql)
>                 Me.objCmd.Connection = objConnection
>                 Me.objDa = New
System.Data.SqlClient.SqlDataAdapter(objCmd)
>                 Me.objDt = New System.Data.DataTable()
>                 Me.objDa.Fill(objDt)
>                 Return objDt
>
> Well there is another observation that this error occures when this
> function is called in a loop for getting many results from different
> queries.
>
> Hope to hear from you soon
> Regards
> Mustafa
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923
>


Message #3 by "Pat" <gannpm@h...> on Thu, 24 Oct 2002 06:01:22
> Hi Mustafa,

I tested your code and could not replicate the error, although I did have 
to
guess at where your code was loading and what the connection object and
strsql looked like.

Can you email me more info so that I can test it further?

Regards,

Bernie Yaeger

----- Original Message -----
From: "Mustafa" <syedmustafashah@f...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Wednesday, October 23, 2002 6:07 AM
Subject: [ado_dotnet] Error!!! (Invalid attemp to read when reader is
closed)


> Hi All!!
> I am using ADO .Net in a windows application in Vb.net. I have a function
> that accepts a query and return the results in a DataTable. It works fine
> for most of the time but some times it starts giving an error
> i.e "System.InvalidoperationException: Invalid attempt to read when the
> reader is closed"
>
> I am not using the reader explicitely. I am using data Adapter and the
> error occures in "DA.Fill(DataTable)" call.
>
> I have searched for this error statement on the web and in MSDN but in
> vain. I hope someone can give me an idea of what should i try.
>
> my code looks like this .....
>
>                 Me.objCmd = New System.Data.SqlClient.SqlCommand(strSql)
>                 Me.objCmd.Connection = objConnection
>                 Me.objDa = New
System.Data.SqlClient.SqlDataAdapter(objCmd)
>                 Me.objDt = New System.Data.DataTable()
>                 Me.objDa.Fill(objDt)
>                 Return objDt
>
> Well there is another observation that this error occures when this
> function is called in a loop for getting many results from different
> queries.
>
> Hope to hear from you soon
> Regards
> Mustafa
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923
>

Guess:
The DataAdatper class handles the opening and closing of the DB 
connection. If there are several instances of this class being opened by 
various users, it may not be "thread safe". In other words, the method may 
be letting other DB connections come from the same method causing some 
method instances to be "out of synch". I know how to do this in Java, but 
I am new to C#. But if you hold C# in a mirror, you see and exact replica 
of Java! Try building your commands manually i.e. write seperate Connect() 
and Disconnect() with you SQL commands. (See Beginning ASP.NET Databases 
Using C# - pg. 237-244)


Message #4 by "Mustafa" <syedmustafashah@f...> on Thu, 24 Oct 2002 08:46:12
Hi Bernie!
Well I got your point. Firstly!! i want to tell you that i am using this 
function for whole project. More than 90 % calls to this function results 
in success. Basically this function is a simple getRecords() function in 
which i send a query and it returns a Datatable. 
There is a perticular function in which this getrecords() is called in a 
loop. THis function produces this error wihile the loop is entered 17th or 
18th time. Some times this error occures when loop is entered 20th or 21st 
time and then the error keeps on coming untill the program is restarted. 
I tried these things.
1. Firstly the connection was global and was closed after the loop. In 
this situation the error was occuring most of the times.
2. Then i made the connecion to open and close in the getrecords() 
function so that the connection gets refereshed. This reduces the number 
of times the error occurs. But it still throws exeption of and on.

Well sometimes it goes on without any error. Another thing that i should 
mention here is that if i calls the function again after the error occures 
then it runs fine for the same call. 

I am very confused now to what to try.

Regards
Mustafa
> > Hi Mustafa,

> I tested your code and could not replicate the error, although I did 
have 
t> o
g> uess at where your code was loading and what the connection object and
s> trsql looked like.

> Can you email me more info so that I can test it further?

> Regards,

> Bernie Yaeger

>>  ---
>>  ASP.NET Distributed Data Applications
>>  This book will inspire you with a range of ideas on how data
>>  can be used to drive Web applications, and how that data can
>>  be most effectively utilized at each level of the design.
>>  Inefficient data use leads to the sort of slow, unresponsive
>>  Web applications that nobody enjoys using. By making good use
>>  of both server and client-side code, we can solve these
>>  problems. This book will arm you with the techniques you need
>>  to build Web applications that fly.
>>  http://www.wrox.com/ACON11.asp?ISBN=1861004923
%> %email.unsub%%.
>> 

> Guess:
T> he DataAdatper class handles the opening and closing of the DB 
c> onnection. If there are several instances of this class being opened by 
v> arious users, it may not be "thread safe". In other words, the method 
may 
b> e letting other DB connections come from the same method causing some 
m> ethod instances to be "out of synch". I know how to do this in Java, 
but 
I>  am new to C#. But if you hold C# in a mirror, you see and exact 
replica 
o> f Java! Try building your commands manually i.e. write seperate Connect
() 
a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET Databases 
U> sing C# - pg. 237-244)

> 
Message #5 by "Bernie Yaeger" <berniey@c...> on Thu, 24 Oct 2002 10:45:22 -0400
Hi Mustafa,

Sounds like a problem having to do with garbage collection.  If there error
were code related, it would throw an exception at the same time all the
time.  What version of windows are your running this on?

If possible, see if you can run the program on xp pro - my guess is it will
no longer error out.  I had a problem like this and the problem turned out
to be the inability of windows to function without explicitly called garbage
collection code.

Regards - hth,
Bernie
----- Original Message -----
From: "Mustafa" <syedmustafashah@f...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Thursday, October 24, 2002 8:46 AM
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
closed)


> Hi Bernie!
> Well I got your point. Firstly!! i want to tell you that i am using this
> function for whole project. More than 90 % calls to this function results
> in success. Basically this function is a simple getRecords() function in
> which i send a query and it returns a Datatable.
> There is a perticular function in which this getrecords() is called in a
> loop. THis function produces this error wihile the loop is entered 17th or
> 18th time. Some times this error occures when loop is entered 20th or 21st
> time and then the error keeps on coming untill the program is restarted.
> I tried these things.
> 1. Firstly the connection was global and was closed after the loop. In
> this situation the error was occuring most of the times.
> 2. Then i made the connecion to open and close in the getrecords()
> function so that the connection gets refereshed. This reduces the number
> of times the error occurs. But it still throws exeption of and on.
>
> Well sometimes it goes on without any error. Another thing that i should
> mention here is that if i calls the function again after the error occures
> then it runs fine for the same call.
>
> I am very confused now to what to try.
>
> Regards
> Mustafa
> > > Hi Mustafa,
>
> > I tested your code and could not replicate the error, although I did
> have
> t> o
> g> uess at where your code was loading and what the connection object and
> s> trsql looked like.
>
> > Can you email me more info so that I can test it further?
>
> > Regards,
>
> > Bernie Yaeger
>
> >>  ---
> >>  ASP.NET Distributed Data Applications
> >>  This book will inspire you with a range of ideas on how data
> >>  can be used to drive Web applications, and how that data can
> >>  be most effectively utilized at each level of the design.
> >>  Inefficient data use leads to the sort of slow, unresponsive
> >>  Web applications that nobody enjoys using. By making good use
> >>  of both server and client-side code, we can solve these
> >>  problems. This book will arm you with the techniques you need
> >>  to build Web applications that fly.
> >>  http://www.wrox.com/ACON11.asp?ISBN=1861004923
> %> %email.unsub%%.
> >>
>
> > Guess:
> T> he DataAdatper class handles the opening and closing of the DB
> c> onnection. If there are several instances of this class being opened by
> v> arious users, it may not be "thread safe". In other words, the method
> may
> b> e letting other DB connections come from the same method causing some
> m> ethod instances to be "out of synch". I know how to do this in Java,
> but
> I>  am new to C#. But if you hold C# in a mirror, you see and exact
> replica
> o> f Java! Try building your commands manually i.e. write seperate Connect
> ()
> a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET Databases
> U> sing C# - pg. 237-244)
>
> >
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923
>


Message #6 by Richard Ainsley <rainsley@p...> on Fri, 25 Oct 2002 09:24:06 -0700
DataReader objects are forward only datasets.  If you close them, of if the
connection times out, you need to start up the DataReader again.  If you are
repeatedly looking for something, consider using datasets and dataAdapters
instead.

Use a data adapter to fill a dataset and forget the problem as the entire
dataset will then be in RAM and will stay there until you do something to
remove it.  If you need subsets of the dataset, access the subsets with
dataView objects which allow you to place filters and sorts on the dataset's
information.  When you are ready to update the SQL database from the
dataset,  use a SQLDataAdapter which will automatically open the conection
to perform updates.




----- Original Message -----
From: "Mustafa" <syedmustafashah@f...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Thursday, October 24, 2002 8:46 AM
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
closed)


> Hi Bernie!
> Well I got your point. Firstly!! i want to tell you that i am using this
> function for whole project. More than 90 % calls to this function results
> in success. Basically this function is a simple getRecords() function in
> which i send a query and it returns a Datatable.
> There is a perticular function in which this getrecords() is called in a
> loop. THis function produces this error wihile the loop is entered 17th or
> 18th time. Some times this error occures when loop is entered 20th or 21st
> time and then the error keeps on coming untill the program is restarted.
> I tried these things.
> 1. Firstly the connection was global and was closed after the loop. In
> this situation the error was occuring most of the times.
> 2. Then i made the connecion to open and close in the getrecords()
> function so that the connection gets refereshed. This reduces the number
> of times the error occurs. But it still throws exeption of and on.
>
> Well sometimes it goes on without any error. Another thing that i should
> mention here is that if i calls the function again after the error occures
> then it runs fine for the same call.
>
> I am very confused now to what to try.
>
> Regards
> Mustafa
> > > Hi Mustafa,
>
> > I tested your code and could not replicate the error, although I did
> have
> t> o
> g> uess at where your code was loading and what the connection object and
> s> trsql looked like.
>
> > Can you email me more info so that I can test it further?
>
> > Regards,
>
> > Bernie Yaeger
>
> >>  ---
> >>  ASP.NET Distributed Data Applications
> >>  This book will inspire you with a range of ideas on how data
> >>  can be used to drive Web applications, and how that data can
> >>  be most effectively utilized at each level of the design.
> >>  Inefficient data use leads to the sort of slow, unresponsive
> >>  Web applications that nobody enjoys using. By making good use
> >>  of both server and client-side code, we can solve these
> >>  problems. This book will arm you with the techniques you need
> >>  to build Web applications that fly.
> >>  http://www.wrox.com/ACON11.asp?ISBN=1861004923
> %> %email.unsub%%.
> >>
>
> > Guess:
> T> he DataAdatper class handles the opening and closing of the DB
> c> onnection. If there are several instances of this class being opened by
> v> arious users, it may not be "thread safe". In other words, the method
> may
> b> e letting other DB connections come from the same method causing some
> m> ethod instances to be "out of synch". I know how to do this in Java,
> but
> I>  am new to C#. But if you hold C# in a mirror, you see and exact
> replica
> o> f Java! Try building your commands manually i.e. write seperate Connect
> ()
> a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET Databases
> U> sing C# - pg. 237-244)
>
> >
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923

Message #7 by "Shah Jee" <syedmustafashah@f...> on Mon, 28 Oct 2002 10:03:49 +0500
Hi Bernie,
I guess you have a point. I was also thinking on the same nodes. But i was
unable to think of a soloution. Now i have solved the problem in some other
fashion. I have removed the loop and fetched all the whole table in one
call. Then i used select statement of datatable to query in the disconnected
table. This has eliminated  the exception throwing conditions.
This also support your idea of unability of garbage collector. By the way I
am using win2000 server but still i am getting this problem.

Thanx anyways for the suggestions.

Regards
Mustafa Shah
----- Original Message -----
From: "Bernie Yaeger" <berniey@c...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Thursday, October 24, 2002 7:45 PM
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
closed)


> Hi Mustafa,
>
> Sounds like a problem having to do with garbage collection.  If there
error
> were code related, it would throw an exception at the same time all the
> time.  What version of windows are your running this on?
>
> If possible, see if you can run the program on xp pro - my guess is it
will
> no longer error out.  I had a problem like this and the problem turned out
> to be the inability of windows to function without explicitly called
garbage
> collection code.
>
> Regards - hth,
> Bernie
> ----- Original Message -----
> From: "Mustafa" <syedmustafashah@f...>
> To: "ADO.NET" <ado_dotnet@p...>
> Sent: Thursday, October 24, 2002 8:46 AM
> Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
> closed)
>
>
> > Hi Bernie!
> > Well I got your point. Firstly!! i want to tell you that i am using this
> > function for whole project. More than 90 % calls to this function
results
> > in success. Basically this function is a simple getRecords() function in
> > which i send a query and it returns a Datatable.
> > There is a perticular function in which this getrecords() is called in a
> > loop. THis function produces this error wihile the loop is entered 17th
or
> > 18th time. Some times this error occures when loop is entered 20th or
21st
> > time and then the error keeps on coming untill the program is restarted.
> > I tried these things.
> > 1. Firstly the connection was global and was closed after the loop. In
> > this situation the error was occuring most of the times.
> > 2. Then i made the connecion to open and close in the getrecords()
> > function so that the connection gets refereshed. This reduces the number
> > of times the error occurs. But it still throws exeption of and on.
> >
> > Well sometimes it goes on without any error. Another thing that i should
> > mention here is that if i calls the function again after the error
occures
> > then it runs fine for the same call.
> >
> > I am very confused now to what to try.
> >
> > Regards
> > Mustafa
> > > > Hi Mustafa,
> >
> > > I tested your code and could not replicate the error, although I did
> > have
> > t> o
> > g> uess at where your code was loading and what the connection object
and
> > s> trsql looked like.
> >
> > > Can you email me more info so that I can test it further?
> >
> > > Regards,
> >
> > > Bernie Yaeger
> >
> > >>  ---
> > >>  ASP.NET Distributed Data Applications
> > >>  This book will inspire you with a range of ideas on how data
> > >>  can be used to drive Web applications, and how that data can
> > >>  be most effectively utilized at each level of the design.
> > >>  Inefficient data use leads to the sort of slow, unresponsive
> > >>  Web applications that nobody enjoys using. By making good use
> > >>  of both server and client-side code, we can solve these
> > >>  problems. This book will arm you with the techniques you need
> > >>  to build Web applications that fly.
> > >>  http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > %> %email.unsub%%.
> > >>
> >
> > > Guess:
> > T> he DataAdatper class handles the opening and closing of the DB
> > c> onnection. If there are several instances of this class being opened
by
> > v> arious users, it may not be "thread safe". In other words, the method
> > may
> > b> e letting other DB connections come from the same method causing some
> > m> ethod instances to be "out of synch". I know how to do this in Java,
> > but
> > I>  am new to C#. But if you hold C# in a mirror, you see and exact
> > replica
> > o> f Java! Try building your commands manually i.e. write seperate
Connect
> > ()
> > a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET
Databases
> > U> sing C# - pg. 237-244)
> >
> > >
> > ---
> > ASP.NET Distributed Data Applications
> > This book will inspire you with a range of ideas on how data
> > can be used to drive Web applications, and how that data can
> > be most effectively utilized at each level of the design.
> > Inefficient data use leads to the sort of slow, unresponsive
> > Web applications that nobody enjoys using. By making good use
> > of both server and client-side code, we can solve these
> > problems. This book will arm you with the techniques you need
> > to build Web applications that fly.
> > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> >
>
>
>
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923
>
>

Message #8 by "Shah Jee" <syedmustafashah@f...> on Mon, 28 Oct 2002 10:54:33 +0500
Hi Richard;
Thanks for the suggestion. I have already done that i.e. i have filled the
required tables in the datatables and i am doing searching on them. But
there is one thing that i must mention here is about your suggestion of
using  SqlDataAdapter. I was already using that ... i have mentioned in my
firast mail that i am not using the reader explicitely. But the problem is
that SqlDataAdapter uses the Reader at the background to fill the tables and
hence it was giving error due the reader that was used explicitely by DA or
Cmd or Connection.



----- Original Message -----
From: "Richard Ainsley" <rainsley@p...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Friday, October 25, 2002 9:24 PM
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
closed)


> DataReader objects are forward only datasets.  If you close them, of if
the
> connection times out, you need to start up the DataReader again.  If you
are
> repeatedly looking for something, consider using datasets and dataAdapters
> instead.
>
> Use a data adapter to fill a dataset and forget the problem as the entire
> dataset will then be in RAM and will stay there until you do something to
> remove it.  If you need subsets of the dataset, access the subsets with
> dataView objects which allow you to place filters and sorts on the
dataset's
> information.  When you are ready to update the SQL database from the
> dataset,  use a SQLDataAdapter which will automatically open the conection
> to perform updates.
>
>
>
>
> ----- Original Message -----
> From: "Mustafa" <syedmustafashah@f...>
> To: "ADO.NET" <ado_dotnet@p...>
> Sent: Thursday, October 24, 2002 8:46 AM
> Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
> closed)
>
>
> > Hi Bernie!
> > Well I got your point. Firstly!! i want to tell you that i am using this
> > function for whole project. More than 90 % calls to this function
results
> > in success. Basically this function is a simple getRecords() function in
> > which i send a query and it returns a Datatable.
> > There is a perticular function in which this getrecords() is called in a
> > loop. THis function produces this error wihile the loop is entered 17th
or
> > 18th time. Some times this error occures when loop is entered 20th or
21st
> > time and then the error keeps on coming untill the program is restarted.
> > I tried these things.
> > 1. Firstly the connection was global and was closed after the loop. In
> > this situation the error was occuring most of the times.
> > 2. Then i made the connecion to open and close in the getrecords()
> > function so that the connection gets refereshed. This reduces the number
> > of times the error occurs. But it still throws exeption of and on.
> >
> > Well sometimes it goes on without any error. Another thing that i should
> > mention here is that if i calls the function again after the error
occures
> > then it runs fine for the same call.
> >
> > I am very confused now to what to try.
> >
> > Regards
> > Mustafa
> > > > Hi Mustafa,
> >
> > > I tested your code and could not replicate the error, although I did
> > have
> > t> o
> > g> uess at where your code was loading and what the connection object
and
> > s> trsql looked like.
> >
> > > Can you email me more info so that I can test it further?
> >
> > > Regards,
> >
> > > Bernie Yaeger
> >
> > >>  ---
> > >>  ASP.NET Distributed Data Applications
> > >>  This book will inspire you with a range of ideas on how data
> > >>  can be used to drive Web applications, and how that data can
> > >>  be most effectively utilized at each level of the design.
> > >>  Inefficient data use leads to the sort of slow, unresponsive
> > >>  Web applications that nobody enjoys using. By making good use
> > >>  of both server and client-side code, we can solve these
> > >>  problems. This book will arm you with the techniques you need
> > >>  to build Web applications that fly.
> > >>  http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > %> %email.unsub%%.
> > >>
> >
> > > Guess:
> > T> he DataAdatper class handles the opening and closing of the DB
> > c> onnection. If there are several instances of this class being opened
by
> > v> arious users, it may not be "thread safe". In other words, the method
> > may
> > b> e letting other DB connections come from the same method causing some
> > m> ethod instances to be "out of synch". I know how to do this in Java,
> > but
> > I>  am new to C#. But if you hold C# in a mirror, you see and exact
> > replica
> > o> f Java! Try building your commands manually i.e. write seperate
Connect
> > ()
> > a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET
Databases
> > U> sing C# - pg. 237-244)
> >
> > >
> > ---
> > ASP.NET Distributed Data Applications
> > This book will inspire you with a range of ideas on how data
> > can be used to drive Web applications, and how that data can
> > be most effectively utilized at each level of the design.
> > Inefficient data use leads to the sort of slow, unresponsive
> > Web applications that nobody enjoys using. By making good use
> > of both server and client-side code, we can solve these
> > problems. This book will arm you with the techniques you need
> > to build Web applications that fly.
> > http://www.wrox.com/ACON11.asp?ISBN=1861004923
>
>
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923
>
>

Message #9 by Richard Ainsley <rainsley@p...> on Mon, 28 Oct 2002 17:31:25 -0800
? It is my understanding that the SQLDataReader is not part of the
sqlDataAdapter.  If indeed the SQLDataadapter instantiates a SQLDataReader,
then I am puzzled by this error should occur.  The dataadapter checks to see
if the connection is closed and opens it if needed (ie: it leaves the
connection open state as it found it on exit any time a connection is
needed).  If you are searching through the already downloaded table, then
there is no need for any SQLDataReader as the data is already present and
the connectioon is likely closed already.

The dataset is a disconnected array of records and other things which you
can search in memory with For Next loops and such.  Further you can apply a
filter and sort to the data after it is memory with dataView objects and use
For Next loops on them too.

There should be a problem like you report if you have coded a Web style
service which can be accessed by more than one thread at a time.  If that is
what you did, then you need to protect larger sections of your code with
semiphores to prevent multiple threads from running the same code at the
same time.

Another possibility that I have experienced and should mention is that using
stored procedures can cause goofy problems.  The IDE wizards do not reliably
put everything together for stored procedures.  In this case poke about the
Windows generated code region and find the SQLcommands -- check that they
reference the correct connection object and also poke around the parameters
list as it fails to define the field names corresponding to parameters...

Hope this helps.  I do not mean to be rude or inattentive.  Let me know how
you are doing...

Richard Ainsley



----- Original Message -----
From: "Shah Jee" <syedmustafashah@f...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Sunday, October 27, 2002 9:54 PM
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
closed)


> Hi Richard;
> Thanks for the suggestion. I have already done that i.e. i have filled the
> required tables in the datatables and i am doing searching on them. But
> there is one thing that i must mention here is about your suggestion of
> using  SqlDataAdapter. I was already using that ... i have mentioned in my
> firast mail that i am not using the reader explicitely. But the problem is
> that SqlDataAdapter uses the Reader at the background to fill the tables
and
> hence it was giving error due the reader that was used explicitely by DA
or
> Cmd or Connection.
>
>
>
> ----- Original Message -----
> From: "Richard Ainsley" <rainsley@p...>
> To: "ADO.NET" <ado_dotnet@p...>
> Sent: Friday, October 25, 2002 9:24 PM
> Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
> closed)
>
>
> > DataReader objects are forward only datasets.  If you close them, of if
> the
> > connection times out, you need to start up the DataReader again.  If you
> are
> > repeatedly looking for something, consider using datasets and
dataAdapters
> > instead.
> >
> > Use a data adapter to fill a dataset and forget the problem as the
entire
> > dataset will then be in RAM and will stay there until you do something
to
> > remove it.  If you need subsets of the dataset, access the subsets with
> > dataView objects which allow you to place filters and sorts on the
> dataset's
> > information.  When you are ready to update the SQL database from the
> > dataset,  use a SQLDataAdapter which will automatically open the
conection
> > to perform updates.
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "Mustafa" <syedmustafashah@f...>
> > To: "ADO.NET" <ado_dotnet@p...>
> > Sent: Thursday, October 24, 2002 8:46 AM
> > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
is
> > closed)
> >
> >
> > > Hi Bernie!
> > > Well I got your point. Firstly!! i want to tell you that i am using
this
> > > function for whole project. More than 90 % calls to this function
> results
> > > in success. Basically this function is a simple getRecords() function
in
> > > which i send a query and it returns a Datatable.
> > > There is a perticular function in which this getrecords() is called in
a
> > > loop. THis function produces this error wihile the loop is entered
17th
> or
> > > 18th time. Some times this error occures when loop is entered 20th or
> 21st
> > > time and then the error keeps on coming untill the program is
restarted.
> > > I tried these things.
> > > 1. Firstly the connection was global and was closed after the loop. In
> > > this situation the error was occuring most of the times.
> > > 2. Then i made the connecion to open and close in the getrecords()
> > > function so that the connection gets refereshed. This reduces the
number
> > > of times the error occurs. But it still throws exeption of and on.
> > >
> > > Well sometimes it goes on without any error. Another thing that i
should
> > > mention here is that if i calls the function again after the error
> occures
> > > then it runs fine for the same call.
> > >
> > > I am very confused now to what to try.
> > >
> > > Regards
> > > Mustafa
> > > > > Hi Mustafa,
> > >
> > > > I tested your code and could not replicate the error, although I did
> > > have
> > > t> o
> > > g> uess at where your code was loading and what the connection object
> and
> > > s> trsql looked like.
> > >
> > > > Can you email me more info so that I can test it further?
> > >
> > > > Regards,
> > >
> > > > Bernie Yaeger
> > >
> > > >>  ---
> > > >>  ASP.NET Distributed Data Applications
> > > >>  This book will inspire you with a range of ideas on how data
> > > >>  can be used to drive Web applications, and how that data can
> > > >>  be most effectively utilized at each level of the design.
> > > >>  Inefficient data use leads to the sort of slow, unresponsive
> > > >>  Web applications that nobody enjoys using. By making good use
> > > >>  of both server and client-side code, we can solve these
> > > >>  problems. This book will arm you with the techniques you need
> > > >>  to build Web applications that fly.
> > > >>  http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > > %> %email.unsub%%.
> > > >>
> > >
> > > > Guess:
> > > T> he DataAdatper class handles the opening and closing of the DB
> > > c> onnection. If there are several instances of this class being
opened
> by
> > > v> arious users, it may not be "thread safe". In other words, the
method
> > > may
> > > b> e letting other DB connections come from the same method causing
some
> > > m> ethod instances to be "out of synch". I know how to do this in
Java,
> > > but
> > > I>  am new to C#. But if you hold C# in a mirror, you see and exact
> > > replica
> > > o> f Java! Try building your commands manually i.e. write seperate
> Connect
> > > ()
> > > a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET
> Databases
> > > U> sing C# - pg. 237-244)
> > >
> > > >
> > > ---
> > > ASP.NET Distributed Data Applications
> > > This book will inspire you with a range of ideas on how data
> > > can be used to drive Web applications, and how that data can
> > > be most effectively utilized at each level of the design.
> > > Inefficient data use leads to the sort of slow, unresponsive
> > > Web applications that nobody enjoys using. By making good use
> > > of both server and client-side code, we can solve these
> > > problems. This book will arm you with the techniques you need
> > > to build Web applications that fly.
> > > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> >
> >
> > ---
> > ASP.NET Distributed Data Applications
> > This book will inspire you with a range of ideas on how data
> > can be used to drive Web applications, and how that data can
> > be most effectively utilized at each level of the design.
> > Inefficient data use leads to the sort of slow, unresponsive
> > Web applications that nobody enjoys using. By making good use
> > of both server and client-side code, we can solve these
> > problems. This book will arm you with the techniques you need
> > to build Web applications that fly.
> > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> >
> >
>
>
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923

Message #10 by "Brian Smith" <bsmith@l...> on Wed, 30 Oct 2002 09:02:41 -0000
Richard,
I think you'll find that a DataAdapter does indeed use a DataReader to
execute the Fill().  The Reader can be disposed of as soon as all of the
records have been loaded. The error that Shah is reporting looks more
likely to relate to a problem in garbage collection and object pooling -
i.e a framework bug...

brian

-----Original Message-----
From: Richard Ainsley [mailto:rainsley@p...] 
Sent: Tue, 29 Oct 2002 01:31
To: ADO.NET
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
is closed)


? It is my understanding that the SQLDataReader is not part of the
sqlDataAdapter.  If indeed the SQLDataadapter instantiates a
SQLDataReader, then I am puzzled by this error should occur.  The
dataadapter checks to see if the connection is closed and opens it if
needed (ie: it leaves the connection open state as it found it on exit
any time a connection is needed).  If you are searching through the
already downloaded table, then there is no need for any SQLDataReader as
the data is already present and the connectioon is likely closed
already.

The dataset is a disconnected array of records and other things which
you can search in memory with For Next loops and such.  Further you can
apply a filter and sort to the data after it is memory with dataView
objects and use For Next loops on them too.

There should be a problem like you report if you have coded a Web style
service which can be accessed by more than one thread at a time.  If
that is what you did, then you need to protect larger sections of your
code with semiphores to prevent multiple threads from running the same
code at the same time.

Another possibility that I have experienced and should mention is that
using stored procedures can cause goofy problems.  The IDE wizards do
not reliably put everything together for stored procedures.  In this
case poke about the Windows generated code region and find the
SQLcommands -- check that they reference the correct connection object
and also poke around the parameters list as it fails to define the field
names corresponding to parameters...

Hope this helps.  I do not mean to be rude or inattentive.  Let me know
how you are doing...

Richard Ainsley



----- Original Message -----
From: "Shah Jee" <syedmustafashah@f...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Sunday, October 27, 2002 9:54 PM
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
is
closed)


> Hi Richard;
> Thanks for the suggestion. I have already done that i.e. i have filled

> the required tables in the datatables and i am doing searching on 
> them. But there is one thing that i must mention here is about your 
> suggestion of using  SqlDataAdapter. I was already using that ... i 
> have mentioned in my firast mail that i am not using the reader 
> explicitely. But the problem is that SqlDataAdapter uses the Reader at

> the background to fill the tables
and
> hence it was giving error due the reader that was used explicitely by 
> DA
or
> Cmd or Connection.
>
>
>
> ----- Original Message -----
> From: "Richard Ainsley" <rainsley@p...>
> To: "ADO.NET" <ado_dotnet@p...>
> Sent: Friday, October 25, 2002 9:24 PM
> Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader

> is
> closed)
>
>
> > DataReader objects are forward only datasets.  If you close them, of

> > if
> the
> > connection times out, you need to start up the DataReader again.  If

> > you
> are
> > repeatedly looking for something, consider using datasets and
dataAdapters
> > instead.
> >
> > Use a data adapter to fill a dataset and forget the problem as the
entire
> > dataset will then be in RAM and will stay there until you do 
> > something
to
> > remove it.  If you need subsets of the dataset, access the subsets 
> > with dataView objects which allow you to place filters and sorts on 
> > the
> dataset's
> > information.  When you are ready to update the SQL database from the

> > dataset,  use a SQLDataAdapter which will automatically open the
conection
> > to perform updates.
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "Mustafa" <syedmustafashah@f...>
> > To: "ADO.NET" <ado_dotnet@p...>
> > Sent: Thursday, October 24, 2002 8:46 AM
> > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when 
> > reader
is
> > closed)
> >
> >
> > > Hi Bernie!
> > > Well I got your point. Firstly!! i want to tell you that i am 
> > > using
this
> > > function for whole project. More than 90 % calls to this function
> results
> > > in success. Basically this function is a simple getRecords() 
> > > function
in
> > > which i send a query and it returns a Datatable.
> > > There is a perticular function in which this getrecords() is 
> > > called in
a
> > > loop. THis function produces this error wihile the loop is entered
17th
> or
> > > 18th time. Some times this error occures when loop is entered 20th

> > > or
> 21st
> > > time and then the error keeps on coming untill the program is
restarted.
> > > I tried these things.
> > > 1. Firstly the connection was global and was closed after the 
> > > loop. In this situation the error was occuring most of the times. 
> > > 2. Then i made the connecion to open and close in the getrecords()

> > > function so that the connection gets refereshed. This reduces the
number
> > > of times the error occurs. But it still throws exeption of and on.
> > >
> > > Well sometimes it goes on without any error. Another thing that i
should
> > > mention here is that if i calls the function again after the error
> occures
> > > then it runs fine for the same call.
> > >
> > > I am very confused now to what to try.
> > >
> > > Regards
> > > Mustafa
> > > > > Hi Mustafa,
> > >
> > > > I tested your code and could not replicate the error, although I

> > > > did
> > > have
> > > t> o
> > > g> uess at where your code was loading and what the connection 
> > > g> object
> and
> > > s> trsql looked like.
> > >
> > > > Can you email me more info so that I can test it further?
> > >
> > > > Regards,
> > >
> > > > Bernie Yaeger
> > >
> > > >>  ---
> > > >>  ASP.NET Distributed Data Applications
> > > >>  This book will inspire you with a range of ideas on how data  
> > > >> can be used to drive Web applications, and how that data can  
> > > >> be most effectively utilized at each level of the design.  
> > > >> Inefficient data use leads to the sort of slow, unresponsive  
> > > >> Web applications that nobody enjoys using. By making good use  
> > > >> of both server and client-side code, we can solve these  
> > > >> problems. This book will arm you with the techniques you need  
> > > >> to build Web applications that fly.  
> > > >> http://www.wrox.com/ACON11.asp?ISBN=1861004923

> > > %> %email.unsub%%.
> > > >>
> > >
> > > > Guess:
> > > T> he DataAdatper class handles the opening and closing of the DB
> > > c> onnection. If there are several instances of this class being
opened
> by
> > > v> arious users, it may not be "thread safe". In other words, the
method
> > > may
> > > b> e letting other DB connections come from the same method 
> > > b> causing
some
> > > m> ethod instances to be "out of synch". I know how to do this in
Java,
> > > but
> > > I>  am new to C#. But if you hold C# in a mirror, you see and 
> > > I> exact
> > > replica
> > > o> f Java! Try building your commands manually i.e. write seperate
> Connect
> > > ()
> > > a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET
> Databases
> > > U> sing C# - pg. 237-244)
> > >
> > > >
> > > ---
> > > ASP.NET Distributed Data Applications
> > > This book will inspire you with a range of ideas on how data can 
> > > be used to drive Web applications, and how that data can be most 
> > > effectively utilized at each level of the design. Inefficient data

> > > use leads to the sort of slow, unresponsive Web applications that 
> > > nobody enjoys using. By making good use of both server and 
> > > client-side code, we can solve these problems. This book will arm 
> > > you with the techniques you need to build Web applications that 
> > > fly. http://www.wrox.com/ACON11.asp?ISBN=1861004923
> >
> >
> > ---
> > ASP.NET Distributed Data Applications
> > This book will inspire you with a range of ideas on how data can be 
> > used to drive Web applications, and how that data can be most 
> > effectively utilized at each level of the design. Inefficient data 
> > use leads to the sort of slow, unresponsive Web applications that 
> > nobody enjoys using. By making good use of both server and 
> > client-side code, we can solve these problems. This book will arm 
> > you with the techniques you need to build Web applications that fly.
> > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> >
> >
>
>
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data can be 
> used to drive Web applications, and how that data can be most 
> effectively utilized at each level of the design. Inefficient data use

> leads to the sort of slow, unresponsive Web applications that nobody 
> enjoys using. By making good use of both server and client-side code, 
> we can solve these problems. This book will arm you with the 
> techniques you need to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923


---
ASP.NET Distributed Data Applications
This book will inspire you with a range of ideas on how data 
can be used to drive Web applications, and how that data can 
be most effectively utilized at each level of the design. 
Inefficient data use leads to the sort of slow, unresponsive 
Web applications that nobody enjoys using. By making good use 
of both server and client-side code, we can solve these 
problems. This book will arm you with the techniques you need 
to build Web applications that fly.
http://www.wrox.com/ACON11.asp?ISBN=1861004923

Message #11 by "Shah Jee" <syedmustafashah@f...> on Wed, 30 Oct 2002 14:20:23 +0500
Hi Richard;
I totally agree to brian; Thats why i have changed my coding style instead
of finding and fixing the causes of this error. After a long period of test
and trail i was unable to fix the errors and then i started reading material
about it. I concluded the same thing as brian mentioned in the mail attached
below.

Regards
Mustafa Shah




----- Original Message -----
From: "Brian Smith" <bsmith@l...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Wednesday, October 30, 2002 2:02 PM
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
closed)


> Richard,
> I think you'll find that a DataAdapter does indeed use a DataReader to
> execute the Fill().  The Reader can be disposed of as soon as all of the
> records have been loaded. The error that Shah is reporting looks more
> likely to relate to a problem in garbage collection and object pooling -
> i.e a framework bug...
>
> brian
>
> -----Original Message-----
> From: Richard Ainsley [mailto:rainsley@p...]
> Sent: Tue, 29 Oct 2002 01:31
> To: ADO.NET
> Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
> is closed)
>
>
> ? It is my understanding that the SQLDataReader is not part of the
> sqlDataAdapter.  If indeed the SQLDataadapter instantiates a
> SQLDataReader, then I am puzzled by this error should occur.  The
> dataadapter checks to see if the connection is closed and opens it if
> needed (ie: it leaves the connection open state as it found it on exit
> any time a connection is needed).  If you are searching through the
> already downloaded table, then there is no need for any SQLDataReader as
> the data is already present and the connectioon is likely closed
> already.
>
> The dataset is a disconnected array of records and other things which
> you can search in memory with For Next loops and such.  Further you can
> apply a filter and sort to the data after it is memory with dataView
> objects and use For Next loops on them too.
>
> There should be a problem like you report if you have coded a Web style
> service which can be accessed by more than one thread at a time.  If
> that is what you did, then you need to protect larger sections of your
> code with semiphores to prevent multiple threads from running the same
> code at the same time.
>
> Another possibility that I have experienced and should mention is that
> using stored procedures can cause goofy problems.  The IDE wizards do
> not reliably put everything together for stored procedures.  In this
> case poke about the Windows generated code region and find the
> SQLcommands -- check that they reference the correct connection object
> and also poke around the parameters list as it fails to define the field
> names corresponding to parameters...
>
> Hope this helps.  I do not mean to be rude or inattentive.  Let me know
> how you are doing...
>
> Richard Ainsley
>
>
>
> ----- Original Message -----
> From: "Shah Jee" <syedmustafashah@f...>
> To: "ADO.NET" <ado_dotnet@p...>
> Sent: Sunday, October 27, 2002 9:54 PM
> Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
> is
> closed)
>
>
> > Hi Richard;
> > Thanks for the suggestion. I have already done that i.e. i have filled
>
> > the required tables in the datatables and i am doing searching on
> > them. But there is one thing that i must mention here is about your
> > suggestion of using  SqlDataAdapter. I was already using that ... i
> > have mentioned in my firast mail that i am not using the reader
> > explicitely. But the problem is that SqlDataAdapter uses the Reader at
>
> > the background to fill the tables
> and
> > hence it was giving error due the reader that was used explicitely by
> > DA
> or
> > Cmd or Connection.
> >
> >
> >
> > ----- Original Message -----
> > From: "Richard Ainsley" <rainsley@p...>
> > To: "ADO.NET" <ado_dotnet@p...>
> > Sent: Friday, October 25, 2002 9:24 PM
> > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
>
> > is
> > closed)
> >
> >
> > > DataReader objects are forward only datasets.  If you close them, of
>
> > > if
> > the
> > > connection times out, you need to start up the DataReader again.  If
>
> > > you
> > are
> > > repeatedly looking for something, consider using datasets and
> dataAdapters
> > > instead.
> > >
> > > Use a data adapter to fill a dataset and forget the problem as the
> entire
> > > dataset will then be in RAM and will stay there until you do
> > > something
> to
> > > remove it.  If you need subsets of the dataset, access the subsets
> > > with dataView objects which allow you to place filters and sorts on
> > > the
> > dataset's
> > > information.  When you are ready to update the SQL database from the
>
> > > dataset,  use a SQLDataAdapter which will automatically open the
> conection
> > > to perform updates.
> > >
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Mustafa" <syedmustafashah@f...>
> > > To: "ADO.NET" <ado_dotnet@p...>
> > > Sent: Thursday, October 24, 2002 8:46 AM
> > > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when
> > > reader
> is
> > > closed)
> > >
> > >
> > > > Hi Bernie!
> > > > Well I got your point. Firstly!! i want to tell you that i am
> > > > using
> this
> > > > function for whole project. More than 90 % calls to this function
> > results
> > > > in success. Basically this function is a simple getRecords()
> > > > function
> in
> > > > which i send a query and it returns a Datatable.
> > > > There is a perticular function in which this getrecords() is
> > > > called in
> a
> > > > loop. THis function produces this error wihile the loop is entered
> 17th
> > or
> > > > 18th time. Some times this error occures when loop is entered 20th
>
> > > > or
> > 21st
> > > > time and then the error keeps on coming untill the program is
> restarted.
> > > > I tried these things.
> > > > 1. Firstly the connection was global and was closed after the
> > > > loop. In this situation the error was occuring most of the times.
> > > > 2. Then i made the connecion to open and close in the getrecords()
>
> > > > function so that the connection gets refereshed. This reduces the
> number
> > > > of times the error occurs. But it still throws exeption of and on.
> > > >
> > > > Well sometimes it goes on without any error. Another thing that i
> should
> > > > mention here is that if i calls the function again after the error
> > occures
> > > > then it runs fine for the same call.
> > > >
> > > > I am very confused now to what to try.
> > > >
> > > > Regards
> > > > Mustafa
> > > > > > Hi Mustafa,
> > > >
> > > > > I tested your code and could not replicate the error, although I
>
> > > > > did
> > > > have
> > > > t> o
> > > > g> uess at where your code was loading and what the connection
> > > > g> object
> > and
> > > > s> trsql looked like.
> > > >
> > > > > Can you email me more info so that I can test it further?
> > > >
> > > > > Regards,
> > > >
> > > > > Bernie Yaeger
> > > >
> > > > >>  ---
> > > > >>  ASP.NET Distributed Data Applications
> > > > >>  This book will inspire you with a range of ideas on how data
> > > > >> can be used to drive Web applications, and how that data can
> > > > >> be most effectively utilized at each level of the design.
> > > > >> Inefficient data use leads to the sort of slow, unresponsive
> > > > >> Web applications that nobody enjoys using. By making good use
> > > > >> of both server and client-side code, we can solve these
> > > > >> problems. This book will arm you with the techniques you need
> > > > >> to build Web applications that fly.
> > > > >> http://www.wrox.com/ACON11.asp?ISBN=1861004923
>
> > > > %> %email.unsub%%.
> > > > >>
> > > >
> > > > > Guess:
> > > > T> he DataAdatper class handles the opening and closing of the DB
> > > > c> onnection. If there are several instances of this class being
> opened
> > by
> > > > v> arious users, it may not be "thread safe". In other words, the
> method
> > > > may
> > > > b> e letting other DB connections come from the same method
> > > > b> causing
> some
> > > > m> ethod instances to be "out of synch". I know how to do this in
> Java,
> > > > but
> > > > I>  am new to C#. But if you hold C# in a mirror, you see and
> > > > I> exact
> > > > replica
> > > > o> f Java! Try building your commands manually i.e. write seperate
> > Connect
> > > > ()
> > > > a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET
> > Databases
> > > > U> sing C# - pg. 237-244)
> > > >
> > > > >
> > > > ---
> > > > ASP.NET Distributed Data Applications
> > > > This book will inspire you with a range of ideas on how data can
> > > > be used to drive Web applications, and how that data can be most
> > > > effectively utilized at each level of the design. Inefficient data
>
> > > > use leads to the sort of slow, unresponsive Web applications that
> > > > nobody enjoys using. By making good use of both server and
> > > > client-side code, we can solve these problems. This book will arm
> > > > you with the techniques you need to build Web applications that
> > > > fly. http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > >
> > >
> > > ---
> > > ASP.NET Distributed Data Applications
> > > This book will inspire you with a range of ideas on how data can be
> > > used to drive Web applications, and how that data can be most
> > > effectively utilized at each level of the design. Inefficient data
> > > use leads to the sort of slow, unresponsive Web applications that
> > > nobody enjoys using. By making good use of both server and
> > > client-side code, we can solve these problems. This book will arm
> > > you with the techniques you need to build Web applications that fly.
> > > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > >
> > >
> >
> >
> > ---
> > ASP.NET Distributed Data Applications
> > This book will inspire you with a range of ideas on how data can be
> > used to drive Web applications, and how that data can be most
> > effectively utilized at each level of the design. Inefficient data use
>
> > leads to the sort of slow, unresponsive Web applications that nobody
> > enjoys using. By making good use of both server and client-side code,
> > we can solve these problems. This book will arm you with the
> > techniques you need to build Web applications that fly.
> > http://www.wrox.com/ACON11.asp?ISBN=1861004923
>
>
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923
>
>
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923
>
>

Message #12 by Richard Ainsley <rainsley@p...> on Wed, 30 Oct 2002 17:12:18 -0800
Brian Smith and Shah Jee:

I have not seen this error yet.  What conditions cause it? Is there any way
to avoid it?  Is there some kind of conflict because the connection used by
the DataReader is also shared with a declared datareader which was not
closed properly?

I must be doing something by accident right as I have very complex code with
many datareaders and SQL command objects sharing the very same connection
object, and have not seen this even once.  Is it just that my test data is
relatively small?

For thse many of us who will eventually stumble into this bug -- can you
lend any insight so we can avoid this one or code a work around?


----- Original Message -----
From: "Shah Jee" <syedmustafashah@f...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Wednesday, October 30, 2002 1:20 AM
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
closed)


> Hi Richard;
> I totally agree to brian; Thats why i have changed my coding style instead
> of finding and fixing the causes of this error. After a long period of
test
> and trail i was unable to fix the errors and then i started reading
material
> about it. I concluded the same thing as brian mentioned in the mail
attached
> below.
>
> Regards
> Mustafa Shah
>
>
>
>
> ----- Original Message -----
> From: "Brian Smith" <bsmith@l...>
> To: "ADO.NET" <ado_dotnet@p...>
> Sent: Wednesday, October 30, 2002 2:02 PM
> Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
> closed)
>
>
> > Richard,
> > I think you'll find that a DataAdapter does indeed use a DataReader to
> > execute the Fill().  The Reader can be disposed of as soon as all of the
> > records have been loaded. The error that Shah is reporting looks more
> > likely to relate to a problem in garbage collection and object pooling -
> > i.e a framework bug...
> >
> > brian
> >
> > -----Original Message-----
> > From: Richard Ainsley [mailto:rainsley@p...]
> > Sent: Tue, 29 Oct 2002 01:31
> > To: ADO.NET
> > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
> > is closed)
> >
> >
> > ? It is my understanding that the SQLDataReader is not part of the
> > sqlDataAdapter.  If indeed the SQLDataadapter instantiates a
> > SQLDataReader, then I am puzzled by this error should occur.  The
> > dataadapter checks to see if the connection is closed and opens it if
> > needed (ie: it leaves the connection open state as it found it on exit
> > any time a connection is needed).  If you are searching through the
> > already downloaded table, then there is no need for any SQLDataReader as
> > the data is already present and the connectioon is likely closed
> > already.
> >
> > The dataset is a disconnected array of records and other things which
> > you can search in memory with For Next loops and such.  Further you can
> > apply a filter and sort to the data after it is memory with dataView
> > objects and use For Next loops on them too.
> >
> > There should be a problem like you report if you have coded a Web style
> > service which can be accessed by more than one thread at a time.  If
> > that is what you did, then you need to protect larger sections of your
> > code with semiphores to prevent multiple threads from running the same
> > code at the same time.
> >
> > Another possibility that I have experienced and should mention is that
> > using stored procedures can cause goofy problems.  The IDE wizards do
> > not reliably put everything together for stored procedures.  In this
> > case poke about the Windows generated code region and find the
> > SQLcommands -- check that they reference the correct connection object
> > and also poke around the parameters list as it fails to define the field
> > names corresponding to parameters...
> >
> > Hope this helps.  I do not mean to be rude or inattentive.  Let me know
> > how you are doing...
> >
> > Richard Ainsley
> >
> >
> >
> > ----- Original Message -----
> > From: "Shah Jee" <syedmustafashah@f...>
> > To: "ADO.NET" <ado_dotnet@p...>
> > Sent: Sunday, October 27, 2002 9:54 PM
> > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
> > is
> > closed)
> >
> >
> > > Hi Richard;
> > > Thanks for the suggestion. I have already done that i.e. i have filled
> >
> > > the required tables in the datatables and i am doing searching on
> > > them. But there is one thing that i must mention here is about your
> > > suggestion of using  SqlDataAdapter. I was already using that ... i
> > > have mentioned in my firast mail that i am not using the reader
> > > explicitely. But the problem is that SqlDataAdapter uses the Reader at
> >
> > > the background to fill the tables
> > and
> > > hence it was giving error due the reader that was used explicitely by
> > > DA
> > or
> > > Cmd or Connection.
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Richard Ainsley" <rainsley@p...>
> > > To: "ADO.NET" <ado_dotnet@p...>
> > > Sent: Friday, October 25, 2002 9:24 PM
> > > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
> >
> > > is
> > > closed)
> > >
> > >
> > > > DataReader objects are forward only datasets.  If you close them, of
> >
> > > > if
> > > the
> > > > connection times out, you need to start up the DataReader again.  If
> >
> > > > you
> > > are
> > > > repeatedly looking for something, consider using datasets and
> > dataAdapters
> > > > instead.
> > > >
> > > > Use a data adapter to fill a dataset and forget the problem as the
> > entire
> > > > dataset will then be in RAM and will stay there until you do
> > > > something
> > to
> > > > remove it.  If you need subsets of the dataset, access the subsets
> > > > with dataView objects which allow you to place filters and sorts on
> > > > the
> > > dataset's
> > > > information.  When you are ready to update the SQL database from the
> >
> > > > dataset,  use a SQLDataAdapter which will automatically open the
> > conection
> > > > to perform updates.
> > > >
> > > >
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Mustafa" <syedmustafashah@f...>
> > > > To: "ADO.NET" <ado_dotnet@p...>
> > > > Sent: Thursday, October 24, 2002 8:46 AM
> > > > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when
> > > > reader
> > is
> > > > closed)
> > > >
> > > >
> > > > > Hi Bernie!
> > > > > Well I got your point. Firstly!! i want to tell you that i am
> > > > > using
> > this
> > > > > function for whole project. More than 90 % calls to this function
> > > results
> > > > > in success. Basically this function is a simple getRecords()
> > > > > function
> > in
> > > > > which i send a query and it returns a Datatable.
> > > > > There is a perticular function in which this getrecords() is
> > > > > called in
> > a
> > > > > loop. THis function produces this error wihile the loop is entered
> > 17th
> > > or
> > > > > 18th time. Some times this error occures when loop is entered 20th
> >
> > > > > or
> > > 21st
> > > > > time and then the error keeps on coming untill the program is
> > restarted.
> > > > > I tried these things.
> > > > > 1. Firstly the connection was global and was closed after the
> > > > > loop. In this situation the error was occuring most of the times.
> > > > > 2. Then i made the connecion to open and close in the getrecords()
> >
> > > > > function so that the connection gets refereshed. This reduces the
> > number
> > > > > of times the error occurs. But it still throws exeption of and on.
> > > > >
> > > > > Well sometimes it goes on without any error. Another thing that i
> > should
> > > > > mention here is that if i calls the function again after the error
> > > occures
> > > > > then it runs fine for the same call.
> > > > >
> > > > > I am very confused now to what to try.
> > > > >
> > > > > Regards
> > > > > Mustafa
> > > > > > > Hi Mustafa,
> > > > >
> > > > > > I tested your code and could not replicate the error, although I
> >
> > > > > > did
> > > > > have
> > > > > t> o
> > > > > g> uess at where your code was loading and what the connection
> > > > > g> object
> > > and
> > > > > s> trsql looked like.
> > > > >
> > > > > > Can you email me more info so that I can test it further?
> > > > >
> > > > > > Regards,
> > > > >
> > > > > > Bernie Yaeger
> > > > >
> > > > > >>  ---
> > > > > >>  ASP.NET Distributed Data Applications
> > > > > >>  This book will inspire you with a range of ideas on how data
> > > > > >> can be used to drive Web applications, and how that data can
> > > > > >> be most effectively utilized at each level of the design.
> > > > > >> Inefficient data use leads to the sort of slow, unresponsive
> > > > > >> Web applications that nobody enjoys using. By making good use
> > > > > >> of both server and client-side code, we can solve these
> > > > > >> problems. This book will arm you with the techniques you need
> > > > > >> to build Web applications that fly.
> > > > > >> http://www.wrox.com/ACON11.asp?ISBN=1861004923
> >
> > > > > %> %email.unsub%%.
> > > > > >>
> > > > >
> > > > > > Guess:
> > > > > T> he DataAdatper class handles the opening and closing of the DB
> > > > > c> onnection. If there are several instances of this class being
> > opened
> > > by
> > > > > v> arious users, it may not be "thread safe". In other words, the
> > method
> > > > > may
> > > > > b> e letting other DB connections come from the same method
> > > > > b> causing
> > some
> > > > > m> ethod instances to be "out of synch". I know how to do this in
> > Java,
> > > > > but
> > > > > I>  am new to C#. But if you hold C# in a mirror, you see and
> > > > > I> exact
> > > > > replica
> > > > > o> f Java! Try building your commands manually i.e. write seperate
> > > Connect
> > > > > ()
> > > > > a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET
> > > Databases
> > > > > U> sing C# - pg. 237-244)
> > > > >
> > > > > >
> > > > > ---
> > > > > ASP.NET Distributed Data Applications
> > > > > This book will inspire you with a range of ideas on how data can
> > > > > be used to drive Web applications, and how that data can be most
> > > > > effectively utilized at each level of the design. Inefficient data
> >
> > > > > use leads to the sort of slow, unresponsive Web applications that
> > > > > nobody enjoys using. By making good use of both server and
> > > > > client-side code, we can solve these problems. This book will arm
> > > > > you with the techniques you need to build Web applications that
> > > > > fly. http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > > >
> > > >
> > > > ---
> > > > ASP.NET Distributed Data Applications
> > > > This book will inspire you with a range of ideas on how data can be
> > > > used to drive Web applications, and how that data can be most
> > > > effectively utilized at each level of the design. Inefficient data
> > > > use leads to the sort of slow, unresponsive Web applications that
> > > > nobody enjoys using. By making good use of both server and
> > > > client-side code, we can solve these problems. This book will arm
> > > > you with the techniques you need to build Web applications that fly.
> > > > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > > >
> > > >
> > >
> > >
> > > ---
> > > ASP.NET Distributed Data Applications
> > > This book will inspire you with a range of ideas on how data can be
> > > used to drive Web applications, and how that data can be most
> > > effectively utilized at each level of the design. Inefficient data use
> >
> > > leads to the sort of slow, unresponsive Web applications that nobody
> > > enjoys using. By making good use of both server and client-side code,
> > > we can solve these problems. This book will arm you with the
> > > techniques you need to build Web applications that fly.
> > > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> >
> >
> > ---
> > ASP.NET Distributed Data Applications
> > This book will inspire you with a range of ideas on how data
> > can be used to drive Web applications, and how that data can
> > be most effectively utilized at each level of the design.
> > Inefficient data use leads to the sort of slow, unresponsive
> > Web applications that nobody enjoys using. By making good use
> > of both server and client-side code, we can solve these
> > problems. This book will arm you with the techniques you need
> > to build Web applications that fly.
> > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> >
> >
> > ---
> > ASP.NET Distributed Data Applications
> > This book will inspire you with a range of ideas on how data
> > can be used to drive Web applications, and how that data can
> > be most effectively utilized at each level of the design.
> > Inefficient data use leads to the sort of slow, unresponsive
> > Web applications that nobody enjoys using. By making good use
> > of both server and client-side code, we can solve these
> > problems. This book will arm you with the techniques you need
> > to build Web applications that fly.
> > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> >
> >
>
>
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923

Message #13 by Richard Ainsley <rainsley@p...> on Thu, 31 Oct 2002 06:19:12 -0800
Brian Smith and Shah Jee:


Is this error the result of either:
1.  Creating a looping construct within which a single connection is used
for at least 1 datareader and either another datareader or a dataadapter.
The first data reader stays open inside the loop.  Conflict: the same
conection is symultaneously used by more than one datareader?

2.  You spawn multiple threads and carelessly allow more than 1 thread to
access the same connection at the same time?

Both of these errors are not "bugs" in dot net, they are bugs in the
programmers design.  SQL server indeed supports multiple threads - but the
connection object connects to ONE of them.  If either of the above
constructs were allowed to run, the result would surely, at minimum, corrupt
data at the SQL server, possibly causing such a massive problem as to render
the SQL server useless.  It is good that an error handler prevents this
headache.

I would be very surprised to learn that this problem is the result of
Opening a datareader, subsequently closing the datareader and its
connection, then subsequently using a data adapter attached to the same
connection object.

Of course I have been surprised before....  But, I follow the protocol in
the above paragraph and have not experienced errors.

If you had had a different experince, I would like to learn more about the
conditions that result in errors.


----- Original Message -----
From: "Richard Ainsley" <rainsley@p...>
To: "ADO.NET" <ado_dotnet@p...>
Sent: Wednesday, October 30, 2002 5:12 PM
Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
closed)


> Brian Smith and Shah Jee:
>
> I have not seen this error yet.  What conditions cause it? Is there any
way
> to avoid it?  Is there some kind of conflict because the connection used
by
> the DataReader is also shared with a declared datareader which was not
> closed properly?
>
> I must be doing something by accident right as I have very complex code
with
> many datareaders and SQL command objects sharing the very same connection
> object, and have not seen this even once.  Is it just that my test data is
> relatively small?
>
> For thse many of us who will eventually stumble into this bug -- can you
> lend any insight so we can avoid this one or code a work around?
>
>
> ----- Original Message -----
> From: "Shah Jee" <syedmustafashah@f...>
> To: "ADO.NET" <ado_dotnet@p...>
> Sent: Wednesday, October 30, 2002 1:20 AM
> Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader is
> closed)
>
>
> > Hi Richard;
> > I totally agree to brian; Thats why i have changed my coding style
instead
> > of finding and fixing the causes of this error. After a long period of
> test
> > and trail i was unable to fix the errors and then i started reading
> material
> > about it. I concluded the same thing as brian mentioned in the mail
> attached
> > below.
> >
> > Regards
> > Mustafa Shah
> >
> >
> >
> >
> > ----- Original Message -----
> > From: "Brian Smith" <bsmith@l...>
> > To: "ADO.NET" <ado_dotnet@p...>
> > Sent: Wednesday, October 30, 2002 2:02 PM
> > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
is
> > closed)
> >
> >
> > > Richard,
> > > I think you'll find that a DataAdapter does indeed use a DataReader to
> > > execute the Fill().  The Reader can be disposed of as soon as all of
the
> > > records have been loaded. The error that Shah is reporting looks more
> > > likely to relate to a problem in garbage collection and object
pooling -
> > > i.e a framework bug...
> > >
> > > brian
> > >
> > > -----Original Message-----
> > > From: Richard Ainsley [mailto:rainsley@p...]
> > > Sent: Tue, 29 Oct 2002 01:31
> > > To: ADO.NET
> > > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
> > > is closed)
> > >
> > >
> > > ? It is my understanding that the SQLDataReader is not part of the
> > > sqlDataAdapter.  If indeed the SQLDataadapter instantiates a
> > > SQLDataReader, then I am puzzled by this error should occur.  The
> > > dataadapter checks to see if the connection is closed and opens it if
> > > needed (ie: it leaves the connection open state as it found it on exit
> > > any time a connection is needed).  If you are searching through the
> > > already downloaded table, then there is no need for any SQLDataReader
as
> > > the data is already present and the connectioon is likely closed
> > > already.
> > >
> > > The dataset is a disconnected array of records and other things which
> > > you can search in memory with For Next loops and such.  Further you
can
> > > apply a filter and sort to the data after it is memory with dataView
> > > objects and use For Next loops on them too.
> > >
> > > There should be a problem like you report if you have coded a Web
style
> > > service which can be accessed by more than one thread at a time.  If
> > > that is what you did, then you need to protect larger sections of your
> > > code with semiphores to prevent multiple threads from running the same
> > > code at the same time.
> > >
> > > Another possibility that I have experienced and should mention is that
> > > using stored procedures can cause goofy problems.  The IDE wizards do
> > > not reliably put everything together for stored procedures.  In this
> > > case poke about the Windows generated code region and find the
> > > SQLcommands -- check that they reference the correct connection object
> > > and also poke around the parameters list as it fails to define the
field
> > > names corresponding to parameters...
> > >
> > > Hope this helps.  I do not mean to be rude or inattentive.  Let me
know
> > > how you are doing...
> > >
> > > Richard Ainsley
> > >
> > >
> > >
> > > ----- Original Message -----
> > > From: "Shah Jee" <syedmustafashah@f...>
> > > To: "ADO.NET" <ado_dotnet@p...>
> > > Sent: Sunday, October 27, 2002 9:54 PM
> > > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when reader
> > > is
> > > closed)
> > >
> > >
> > > > Hi Richard;
> > > > Thanks for the suggestion. I have already done that i.e. i have
filled
> > >
> > > > the required tables in the datatables and i am doing searching on
> > > > them. But there is one thing that i must mention here is about your
> > > > suggestion of using  SqlDataAdapter. I was already using that ... i
> > > > have mentioned in my firast mail that i am not using the reader
> > > > explicitely. But the problem is that SqlDataAdapter uses the Reader
at
> > >
> > > > the background to fill the tables
> > > and
> > > > hence it was giving error due the reader that was used explicitely
by
> > > > DA
> > > or
> > > > Cmd or Connection.
> > > >
> > > >
> > > >
> > > > ----- Original Message -----
> > > > From: "Richard Ainsley" <rainsley@p...>
> > > > To: "ADO.NET" <ado_dotnet@p...>
> > > > Sent: Friday, October 25, 2002 9:24 PM
> > > > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when
reader
> > >
> > > > is
> > > > closed)
> > > >
> > > >
> > > > > DataReader objects are forward only datasets.  If you close them,
of
> > >
> > > > > if
> > > > the
> > > > > connection times out, you need to start up the DataReader again.
If
> > >
> > > > > you
> > > > are
> > > > > repeatedly looking for something, consider using datasets and
> > > dataAdapters
> > > > > instead.
> > > > >
> > > > > Use a data adapter to fill a dataset and forget the problem as the
> > > entire
> > > > > dataset will then be in RAM and will stay there until you do
> > > > > something
> > > to
> > > > > remove it.  If you need subsets of the dataset, access the subsets
> > > > > with dataView objects which allow you to place filters and sorts
on
> > > > > the
> > > > dataset's
> > > > > information.  When you are ready to update the SQL database from
the
> > >
> > > > > dataset,  use a SQLDataAdapter which will automatically open the
> > > conection
> > > > > to perform updates.
> > > > >
> > > > >
> > > > >
> > > > >
> > > > > ----- Original Message -----
> > > > > From: "Mustafa" <syedmustafashah@f...>
> > > > > To: "ADO.NET" <ado_dotnet@p...>
> > > > > Sent: Thursday, October 24, 2002 8:46 AM
> > > > > Subject: [ado_dotnet] Re: Error!!! (Invalid attemp to read when
> > > > > reader
> > > is
> > > > > closed)
> > > > >
> > > > >
> > > > > > Hi Bernie!
> > > > > > Well I got your point. Firstly!! i want to tell you that i am
> > > > > > using
> > > this
> > > > > > function for whole project. More than 90 % calls to this
function
> > > > results
> > > > > > in success. Basically this function is a simple getRecords()
> > > > > > function
> > > in
> > > > > > which i send a query and it returns a Datatable.
> > > > > > There is a perticular function in which this getrecords() is
> > > > > > called in
> > > a
> > > > > > loop. THis function produces this error wihile the loop is
entered
> > > 17th
> > > > or
> > > > > > 18th time. Some times this error occures when loop is entered
20th
> > >
> > > > > > or
> > > > 21st
> > > > > > time and then the error keeps on coming untill the program is
> > > restarted.
> > > > > > I tried these things.
> > > > > > 1. Firstly the connection was global and was closed after the
> > > > > > loop. In this situation the error was occuring most of the
times.
> > > > > > 2. Then i made the connecion to open and close in the
getrecords()
> > >
> > > > > > function so that the connection gets refereshed. This reduces
the
> > > number
> > > > > > of times the error occurs. But it still throws exeption of and
on.
> > > > > >
> > > > > > Well sometimes it goes on without any error. Another thing that
i
> > > should
> > > > > > mention here is that if i calls the function again after the
error
> > > > occures
> > > > > > then it runs fine for the same call.
> > > > > >
> > > > > > I am very confused now to what to try.
> > > > > >
> > > > > > Regards
> > > > > > Mustafa
> > > > > > > > Hi Mustafa,
> > > > > >
> > > > > > > I tested your code and could not replicate the error, although
I
> > >
> > > > > > > did
> > > > > > have
> > > > > > t> o
> > > > > > g> uess at where your code was loading and what the connection
> > > > > > g> object
> > > > and
> > > > > > s> trsql looked like.
> > > > > >
> > > > > > > Can you email me more info so that I can test it further?
> > > > > >
> > > > > > > Regards,
> > > > > >
> > > > > > > Bernie Yaeger
> > > > > >
> > > > > > >>  ---
> > > > > > >>  ASP.NET Distributed Data Applications
> > > > > > >>  This book will inspire you with a range of ideas on how data
> > > > > > >> can be used to drive Web applications, and how that data can
> > > > > > >> be most effectively utilized at each level of the design.
> > > > > > >> Inefficient data use leads to the sort of slow, unresponsive
> > > > > > >> Web applications that nobody enjoys using. By making good use
> > > > > > >> of both server and client-side code, we can solve these
> > > > > > >> problems. This book will arm you with the techniques you need
> > > > > > >> to build Web applications that fly.
> > > > > > >> http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > > > > > >>  ---
> > > > > > >>  Change your mail options at http://p2p.wrox.com/manager.asp
or
> > >
> > > > > > %> %email.unsub%%.
> > > > > > >>
> > > > > >
> > > > > > > Guess:
> > > > > > T> he DataAdatper class handles the opening and closing of the
DB
> > > > > > c> onnection. If there are several instances of this class being
> > > opened
> > > > by
> > > > > > v> arious users, it may not be "thread safe". In other words,
the
> > > method
> > > > > > may
> > > > > > b> e letting other DB connections come from the same method
> > > > > > b> causing
> > > some
> > > > > > m> ethod instances to be "out of synch". I know how to do this
in
> > > Java,
> > > > > > but
> > > > > > I>  am new to C#. But if you hold C# in a mirror, you see and
> > > > > > I> exact
> > > > > > replica
> > > > > > o> f Java! Try building your commands manually i.e. write
seperate
> > > > Connect
> > > > > > ()
> > > > > > a> nd Disconnect() with you SQL commands. (See Beginning ASP.NET
> > > > Databases
> > > > > > U> sing C# - pg. 237-244)
> > > > > >
> > > > > > >
> > > > > > ---
> > > > > > ASP.NET Distributed Data Applications
> > > > > > This book will inspire you with a range of ideas on how data can
> > > > > > be used to drive Web applications, and how that data can be most
> > > > > > effectively utilized at each level of the design. Inefficient
data
> > >
> > > > > > use leads to the sort of slow, unresponsive Web applications
that
> > > > > > nobody enjoys using. By making good use of both server and
> > > > > > client-side code, we can solve these problems. This book will
arm
> > > > > > you with the techniques you need to build Web applications that
> > > > > > fly. http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > > > >
> > > > >
> > > > > ---
> > > > > ASP.NET Distributed Data Applications
> > > > > This book will inspire you with a range of ideas on how data can
be
> > > > > used to drive Web applications, and how that data can be most
> > > > > effectively utilized at each level of the design. Inefficient data
> > > > > use leads to the sort of slow, unresponsive Web applications that
> > > > > nobody enjoys using. By making good use of both server and
> > > > > client-side code, we can solve these problems. This book will arm
> > > > > you with the techniques you need to build Web applications that
fly.
> > > > > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > > > >
> > > > >
> > > >
> > > >
> > > > ---
> > > > ASP.NET Distributed Data Applications
> > > > This book will inspire you with a range of ideas on how data can be
> > > > used to drive Web applications, and how that data can be most
> > > > effectively utilized at each level of the design. Inefficient data
use
> > >
> > > > leads to the sort of slow, unresponsive Web applications that nobody
> > > > enjoys using. By making good use of both server and client-side
code,
> > > > we can solve these problems. This book will arm you with the
> > > > techniques you need to build Web applications that fly.
> > > > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > >
> > >
> > > ---
> > > ASP.NET Distributed Data Applications
> > > This book will inspire you with a range of ideas on how data
> > > can be used to drive Web applications, and how that data can
> > > be most effectively utilized at each level of the design.
> > > Inefficient data use leads to the sort of slow, unresponsive
> > > Web applications that nobody enjoys using. By making good use
> > > of both server and client-side code, we can solve these
> > > problems. This book will arm you with the techniques you need
> > > to build Web applications that fly.
> > > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > >
> > >
> > > ---
> > > ASP.NET Distributed Data Applications
> > > This book will inspire you with a range of ideas on how data
> > > can be used to drive Web applications, and how that data can
> > > be most effectively utilized at each level of the design.
> > > Inefficient data use leads to the sort of slow, unresponsive
> > > Web applications that nobody enjoys using. By making good use
> > > of both server and client-side code, we can solve these
> > > problems. This book will arm you with the techniques you need
> > > to build Web applications that fly.
> > > http://www.wrox.com/ACON11.asp?ISBN=1861004923
> > >
> > >
> >
> >
> > ---
> > ASP.NET Distributed Data Applications
> > This book will inspire you with a range of ideas on how data
> > can be used to drive Web applications, and how that data can
> > be most effectively utilized at each level of the design.
> > Inefficient data use leads to the sort of slow, unresponsive
> > Web applications that nobody enjoys using. By making good use
> > of both server and client-side code, we can solve these
> > problems. This book will arm you with the techniques you need
> > to build Web applications that fly.
> > http://www.wrox.com/ACON11.asp?ISBN=1861004923
>
>
> ---
> ASP.NET Distributed Data Applications
> This book will inspire you with a range of ideas on how data
> can be used to drive Web applications, and how that data can
> be most effectively utilized at each level of the design.
> Inefficient data use leads to the sort of slow, unresponsive
> Web applications that nobody enjoys using. By making good use
> of both server and client-side code, we can solve these
> problems. This book will arm you with the techniques you need
> to build Web applications that fly.
> http://www.wrox.com/ACON11.asp?ISBN=1861004923


  Return to Index