Old topic scratched again -- "already an open DataReader"

C

Chirag Shukla

Guys,

I didnt need multiple recordsets open in .NET until today and it seems
that only 1 datareader can be opened per connection. I think that is
really silly. Using SQL Server 2000 and VB.NET (and C#), I wanted to
upgrade an old, very stable VB application to Framework 1.1.

The deal is that RECORDSET1 scrolls through a group of rows and while
looping, does a few calculations. Under certain conditions, it needs to
get data from another table through RECORDSET2. It was way too simple
in ADO.

ADO
open rs -- loop ----- if result is funny, call another RS and seek data
before closing this RS -- complete the remaining processes ------- end
the loop and close the first rs
~ GetRows() was helpful in ADO ~

ADO.NET doesnt help much with datareader
open reader -- loop ------- if result is funny, call procedure that
opens another connection and another attached READER, seek data before
closing this READER and connection -- complete the remaining processes
-------- end the loop and close the first reader

Is there a better way than above to seek data from another recordset
while looping through the first recordset? Suggestions are welcome.

IDE: VS 2003, Framework 1.1 SP1

Thanks.

Chirag Shukla.
 
O

Otis Mukinfus

Guys,

I didnt need multiple recordsets open in .NET until today and it seems
that only 1 datareader can be opened per connection. I think that is
really silly. Using SQL Server 2000 and VB.NET (and C#), I wanted to
upgrade an old, very stable VB application to Framework 1.1.

The deal is that RECORDSET1 scrolls through a group of rows and while
looping, does a few calculations. Under certain conditions, it needs to
get data from another table through RECORDSET2. It was way too simple
in ADO.

ADO
open rs -- loop ----- if result is funny, call another RS and seek data
before closing this RS -- complete the remaining processes ------- end
the loop and close the first rs
~ GetRows() was helpful in ADO ~

ADO.NET doesnt help much with datareader
open reader -- loop ------- if result is funny, call procedure that
opens another connection and another attached READER, seek data before
closing this READER and connection -- complete the remaining processes
-------- end the loop and close the first reader

Is there a better way than above to seek data from another recordset
while looping through the first recordset? Suggestions are welcome.

IDE: VS 2003, Framework 1.1 SP1

Thanks.

Chirag Shukla.

Chirag,

You will have to open two connections and two readers. You can, However use the
same connection string for both.
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
M

Marina Levit [MVP]

You can either not use datareaders, and use a datatable instead for the
outer loop, or both.
Or you can just create a separate connection.

Either way, pretty trivial to implement.
 

Ask a Question

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

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

Ask a Question

Top