query result size RRS feed

  • Question

  • When I execute a select query that returns several rows how can I measure result rows size in KB?
    Wednesday, August 25, 2010 2:10 PM


  • The following might be good enough for you.  Assuming SqlConnection -- other providers may or may not have something similar.

    Set the StatisticsEnabled property = true on the connection.

    Use the RetrieveStatistics method to obtain the stats.  There will be a "BytesReceived" in the Hashtable.  Divide by total number of rows to get the average per row.

    You can use ResetStatistics prior to your query, or you can retrieve the stats before and after your query and compute the difference.

    If this does not work, you might be on your own.  You'll need to loop through the data and use your knowledge of the data types and how values are represented to tally up the bytes.



    Wednesday, August 25, 2010 11:26 PM