odbcdatareader hangs on close
-
I have a problem when trying to close a connection or the odbcdatareader if I stop it from doing
Read()
before it would normally be done it hangs. I saw something similar when I Googled this a while ago, but can't find it now. Apparently, thewhile(dr.Read())
doesn't actually stop even though I used abreak;
to get out of thewhile()
loop. Anybody run into this before?My Music | My Pics | My Articles BlackDice
-
I have a problem when trying to close a connection or the odbcdatareader if I stop it from doing
Read()
before it would normally be done it hangs. I saw something similar when I Googled this a while ago, but can't find it now. Apparently, thewhile(dr.Read())
doesn't actually stop even though I used abreak;
to get out of thewhile()
loop. Anybody run into this before?My Music | My Pics | My Articles BlackDice
-
show is a small code snippet of the loop. I have a feeling you're missing something that is causing the loop to continue, and not actually hitting the line to break out of the loop.
No, I don't think that's it because it breaks from the loop with no problem. I put a breakpoint on the line immediately following the loop and it goes directly there with no problem. This function is being done in a thread of its own so that the user can press 'Cancel' and also updates the UI correctly. Here's a snippet of what I'm doing:
while (statreader.Read() && !m_bCancel) { stemp = statreader["aj_vchar"].ToString(); //do other stuff here this.progressBar1.Increment(1); } this.progressBar1.Value = 0; //breakpoint here,stops here soon as I press 'Cancel' statreader.Close(); //this line hangs for a LONG time (~10 minutes)
I've tried calling Close() on the connection first. I've tried calling Dispose() instead, and I've tried not closing it at all to see what happens when it goes out of scope (statreader). No matter what, this reader hangs on close depening on how many records are in the reader. When I try it on a test database that returns only a few thousand records, Close() only takes a few seconds. When I try it on a database with about 400,000 records being returned, it takes about 10 minutes for Close() to finish executing.
My Music | My Pics | My Articles BlackDice
-
No, I don't think that's it because it breaks from the loop with no problem. I put a breakpoint on the line immediately following the loop and it goes directly there with no problem. This function is being done in a thread of its own so that the user can press 'Cancel' and also updates the UI correctly. Here's a snippet of what I'm doing:
while (statreader.Read() && !m_bCancel) { stemp = statreader["aj_vchar"].ToString(); //do other stuff here this.progressBar1.Increment(1); } this.progressBar1.Value = 0; //breakpoint here,stops here soon as I press 'Cancel' statreader.Close(); //this line hangs for a LONG time (~10 minutes)
I've tried calling Close() on the connection first. I've tried calling Dispose() instead, and I've tried not closing it at all to see what happens when it goes out of scope (statreader). No matter what, this reader hangs on close depening on how many records are in the reader. When I try it on a test database that returns only a few thousand records, Close() only takes a few seconds. When I try it on a database with about 400,000 records being returned, it takes about 10 minutes for Close() to finish executing.
My Music | My Pics | My Articles BlackDice
-
Can you show me where you're opening the connection? I'm guessing this would shed more light. Are you creating the DataReader object with the option "commandbehavior.closeconnection"?
The following comes directly before what I posted earlier:
using (OdbcConnection conn = new OdbcConnection(source)) { conn.Open(); statcmd = new OdbcCommand("select * from tblPeople", conn); statcmd = new OdbcCommand(sql, conn); OdbcDataReader statreader = statcmd.ExecuteReader();
No, I'm not using "commandbehavior.closeconnection" option. Never knew it existed.
My Music | My Pics | My Articles BlackDice
-
The following comes directly before what I posted earlier:
using (OdbcConnection conn = new OdbcConnection(source)) { conn.Open(); statcmd = new OdbcCommand("select * from tblPeople", conn); statcmd = new OdbcCommand(sql, conn); OdbcDataReader statreader = statcmd.ExecuteReader();
No, I'm not using "commandbehavior.closeconnection" option. Never knew it existed.
My Music | My Pics | My Articles BlackDice
-
Can you show me where you're opening the connection? I'm guessing this would shed more light. Are you creating the DataReader object with the option "commandbehavior.closeconnection"?
-
Just a shot in the dark, can you use a OleDb instead of ODBC and see if the problem persists?
-
Just a shot in the dark, can you use a OleDb instead of ODBC and see if the problem persists?
-
I have a problem when trying to close a connection or the odbcdatareader if I stop it from doing
Read()
before it would normally be done it hangs. I saw something similar when I Googled this a while ago, but can't find it now. Apparently, thewhile(dr.Read())
doesn't actually stop even though I used abreak;
to get out of thewhile()
loop. Anybody run into this before?My Music | My Pics | My Articles BlackDice
MSDN2: DataReader.Close Method [^] Remarks You should close data readers when the consumer has completed reading data or no longer wishes to read any more data. Closing the reader ensures that output parameters, if any, are populated. Depending on the provider implementation, the Close method may wait for the data reader to finish returning all of the specified data before closing. Compare to the Terminate[^] method. Suggestion: If you cannot find a provider that supports the Terminate method, you could split your SQL into chunks of 10,000 or so:
select TOP 10000 * from tblPeople where PeopleID > @nLastID order by PeopleID
Looping and creating a new reader each time until you're done, or the user cancels.--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
-
MSDN2: DataReader.Close Method [^] Remarks You should close data readers when the consumer has completed reading data or no longer wishes to read any more data. Closing the reader ensures that output parameters, if any, are populated. Depending on the provider implementation, the Close method may wait for the data reader to finish returning all of the specified data before closing. Compare to the Terminate[^] method. Suggestion: If you cannot find a provider that supports the Terminate method, you could split your SQL into chunks of 10,000 or so:
select TOP 10000 * from tblPeople where PeopleID > @nLastID order by PeopleID
Looping and creating a new reader each time until you're done, or the user cancels.--EricDV Sig--------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters
EricDV wrote:
Depending on the provider implementation, the Close method may wait for the data reader to finish returning all of the specified data before closing.
Right. I knew I remembered seeing that somewhere. However, the OdbcDataReader doesn't support the Terminate() method. I had already thought about the 'Top xxxx' method, but I was trying to avoid that if possible. Plus, on the database I'm doing it on now, there's about 3 million records, and it's already going to take hours to process those without getting all these different dataSets. Thanks for your help, though :(
My Music | My Pics | My Articles BlackDice