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:
- Serializing the data to find out the size. Too slow, especially for large requests.
- sizeof. We are dealing with objects of unknown type.
- Marshal.sizeof. We are dealing with managed objects.
- 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.
- 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.
精彩评论