开发者

C# SqlCommand bytes transferred size

I am writing a Sql client in C#, and would like to be able to track the data usage of Sql commands at a single point. From what I can tell, there is no simple way to do this.

My function to get the data back from the SqlCommand looks something like this:

private static void ExecuteReaderCallback(IAsyncResult async开发者_运维百科)
{
    DBReqWrapper RequestObject = (DBReqWrapper)async.AsyncState;
    SqlDataReader ResponseReader = command.EndExecuteReader(async);
    if (ResponseReader.HasRows)
    {
          while (ResponseReader.Read())
         {
              object[] NewResponse = new object[ResponseReader.FieldCount];
              ResponseReader.GetValues(NewResponse);

              // Processing omitted
         }
    }

    ResponseReader.Close();
}

What I don't think will work:

  1. Serializing the data to find out the size. Too slow, especially for large requests.
  2. sizeof. We are dealing with objects of unknown type.
  3. Marshal.sizeof. We are dealing with managed objects.
  4. Checking the application total memory. This is a multi-threaded application that will have many concurrent requests being processed and memory totals will be unreliable.
  5. SqlDataReader::GetBytes(). This command is only valid for a subset of types.

Any help is appreciated, thanks!


If you're looking to count how much data is streamed across the 'net, none of those will really work. SQL Server uses, as its application-level wire format, a protocol called TDS (Tabular Data Stream).

I think that performance counters might be your friend here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜