none
System.Data.IDataReader performing slow RRS feed

  • Question

  • Hello All,

    I am using following lines of code to Retrive data from database  :

    while (IDataReaderObject.Read())
    {
    }

    there are only about 4000 records and 4 columns and this blank loop is taking about 1 to 1.30 min. to execute...

    can any one help me for this ??????

    data is in following format :

    Col1      Col2          Col3        Col4

    ----------------------------------------

    A          D17081    38.17       98.42
    A          D18252    20.70       99.47
    A          D16141    52.82         0.00

    Tuesday, July 31, 2012 6:39 AM

Answers

  • How much time it just takes to execute the query that command associated with IDataReader uses? Just that you have ruled out that this is not query performance problem and retrieving data with just executing query itself is much more faster than with IDataReader. Usually in data reader performance issues you should first rule out that bad performance is not because query that retrieves the data is not performing well.
    Wednesday, August 1, 2012 6:38 PM

All replies

  • Hi Yashpalsinh,

    Welcome to the MSDN Forum.

    So how about this method: http://msdn.microsoft.com/en-us/library/s13t2cs5 it retrieves the data one time. It will be faster than IDataReader.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Wednesday, August 1, 2012 6:13 AM
    Moderator
  • Hello Mike

    Thank You for your reply

    but i need to read date from database while your link describes ExecuteNonQuery() which can only execute query in database, and can retrive only numbers of rows affected.

    I am retrieving data in ObjLst1 using following logic :

    1:     ObjectType obj1;

    2:     List<ObjectType > ObjLst1= new List<ObjectType >();

    3:     while (IDataReaderObject.Read())
    4:    {
    5:             obj1 = new ObjectType();
    6:             obj1 .property1= IDataReaderObject["property1"].ToString();

    7:             ObjLst1.Add(obj1);

    8:     }

    and the While loop is taking too much time even if i comment lines 5,6,and 7

    so can you please help me for this ?

    Wednesday, August 1, 2012 9:28 AM
  • How much time it just takes to execute the query that command associated with IDataReader uses? Just that you have ruled out that this is not query performance problem and retrieving data with just executing query itself is much more faster than with IDataReader. Usually in data reader performance issues you should first rule out that bad performance is not because query that retrieves the data is not performing well.
    Wednesday, August 1, 2012 6:38 PM
  • Hi Yashpa,

    Sorry for the wrong link, I actually don't mean ExecuteNoquery, but DataAdapter.Fill, so would you like to try it again.

    And I agree with MasaSam, please check the execute time, it may be the root cause which making your loop slow.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, August 2, 2012 2:06 AM
    Moderator
  • Hi Yashpalsinh,

    I think MasaSam is correct. You shoud check your query and the table. There might be a mis understand. When you execute ExecuteReader, it doesn't means all the result is ready to client. Once you try to read, it will find next result, that can cause the reading sunsume a lot of time.

    So if the query is design in a proper way, or proper indexes added, the reading result will be improved a lot.

    Monday, June 22, 2020 9:07 AM