.NETGURU
OleDbReader, can I short circuit for performance?
Messages   Related Types
This message was discovered on microsoft.public.dotnet.framework.adonet.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.
Post a new message to this list...

Sue (VIP)
Hi,
I am experimenting with the OleDbReader. Here is snippet of my code. I want
to close the reader after reading 1 row in code. (the "reading 1 row" is a
mere example. In actual application, the sampling generator determines which
rows (the selected samples) and how many (sample size) to accept for
processing.)
OleDbReader reader = cmd.ExecuteReader(Command.Behavior.CloseConnection);
int done =0;
string data;
while (reader.Read() && done == 0)
{
data = reader.GetString(0).ToString();
done = 1;
}
reader.Close();
next statement
The code took about 5 minutes before the debug stops at next statement. If
I remove the "done==0" condition, the code took just as long -- about 5
minutes. This observation indicates the reader is reading on until it has
read the last row before it closes, regardless whether the while-loop is
finished prematurely or not.

Is there a way to interrupt the while-loop and force the reader to close
immediately?
Thanks. Sue

Reply to this message...
 
    
David Browne
"Sue" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Not necessarilly. It might indicate that your query takes almost 5 minutes
to produce the first row, and very little time to read all the returned
rows.

David

Reply to this message...
 
    
Sue (VIP)
David, thank you for responding.
That is interesting. I was able to see the data retrieved (in the
while-loop). After the debug steps at the 'reader.Close();' statement, it
took the long 5-min. time before going to the next statement.
My query is "select * from aTable", aTable has 22 columns, row size = 450K.
Sue
"David Browne" wrote:

[Original message clipped]

Reply to this message...
 
    
Miha Markic [MVP C#]
Sue,

"Sue" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

I think that Bill explained the behaviour (why Close takes such long time in
your case)...

--
Miha Markic [MVP C#] - RightHand .NET consulting & development
miha at rthand com
www.rthand.com

Reply to this message...
 
    
William \(Bill\) Vaughn
This is by design. When you ask for 100 or 10000 rows to be piped to your
app with the DataReader, the engine provides those rows--whether you use
them all or not. If you close the Reader, ADO.NET has no choice but to
comply with your first request and fetch all of the rows to empty the pipe.
It's better to:
a) Ask for just the rows you need
b) If you have to close the reader before EOF, use the Cancel method on
the Command. This (might) stop the flow of rows--assuming the server can
handle it.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________

"Sue" <Click here to reveal e-mail address> wrote in message
news:Click here to reveal e-mail address...
[Original message clipped]

Reply to this message...
 
    
Sue (VIP)
Thank you all for your help. I will move the functionality to the server
side. This way only the rows needed are returned.
Sue

"William (Bill) Vaughn" wrote:

[Original message clipped]

Reply to this message...
 
 
System.Web.UI.MobileControls.Command




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification