Groups | Blog | Home
all groups > dotnet faqs > january 2004 >

dotnet faqs : Two SqlDataReader for the same connection



Marina
1/12/2004 11:31:32 AM
It is not possible to have 2 open data readers on the same connection at the
same time.

Either use 2 connections, or use a datatable/dataset for the result of one
or both of your queries.

[quoted text, click to view]

William Ryan
1/12/2004 12:48:41 PM
Close the first datareader or use the CommandBehavior.CloseConnection
www.knowdotnet.com/articles/schemas2.html
.. If you close the reader, you won't have to reopen the connection which
may or may not be appropriate depending on your particular needs. ANother
thing...you may want to use a new connection and just reuse the
connectionstring and throw in a try/catch/finally to make sure things get
cleaned up if anything goes wrong.

HTH,

Bill
[quoted text, click to view]

Ruslan
1/12/2004 6:21:37 PM
Hello,



I have:





Method1()

{

SqlDataReader dr = new DataReader();

....

while (dr.Read)

{

Method2()

}

}



Method2()

{

SqlDataReader dr = new DataReader();

....

while (dr.Read)

{

Method2()

}

}



I use the same connection for both SqlDataReader. It's logically what error
appears, when the "dr.Read()" from the "Method2 is called, because there is
one open connection for the first SqldDataReader. Is it possible to do
something what the both SqlDataReader use the same connection?



Thanks,



Ruslan

Ruslan
1/13/2004 9:52:04 AM
Thank you, but I need to use the same connection and not to close the first
reader, because when I go back to Method1 from Method2 it needs the reader
(dr.Read()).

I think it is not possible and I need to use DataAdapter.





[quoted text, click to view]

AddThis Social Bookmark Button