RE: SqlDataReader performance



WenYuan

To address some of your additional comments and questions:

I'm not looking for the "string keyvalue =
dr[keyname].ToString()" performance, I'm trying to understand general
DataReader performance.

I'm running in release mode in a production environment.

ADO.NET from .net framework 1.1

Thanks for your reply

Jan

--
Do or die..


"WenYuan Wang" wrote:

Hi Jan,

First of all, I'd like to confirm my understanding of your issue.
According to your description, I understand that you want to know why it
will take a long time to execute the statement "string keyvalue =
dr[keyname].ToString()".
If I misunderstand anything here, please don't hesitate to correct me.

The first thing we have to do is to check which mode you have set when you
do the test.
There will be a performance issue when we use DEBUG mode.
If we want to get more performance, we should change the mode to RELEASE.

Second, as Shawn said, GetValue would call GetOrdinal first, if we're
looping through a large rowset GetOrdinal might be called every single
time. Instead, only call it once.
Try this instead:
dr = cmd.ExecuteReader();
string keyvalue = "";
int ordinal = dr.GetOrdinal(keyname);
while(dr.Read())
{
keyvalue = dr[ordinal].ToString();
...
}

Last but not least, I'm afraid I don't think it will take a long time to
execute the statement "string keyvalue = dr[keyname].ToString()". It seems
like "dr.Read()" is time consuming.
Would you mind telling us which version of ADO.net your program run on?
I'll perform more research on it.

If there is anything unclear, please feel free to reply me here. We will
follow up.
I'm glad to work with you.
Sincerely,
WenYuan


.


Loading