When executing T-SQL queries via Management Studio, I can use SET STATISTICS IO ON
and SET STATISTICS TIME ON
to capture statistics for query tuning.
How can I gather the same statistics info when I'm using .NET client APIs to execute T-SQL queries instead of using Mangaement Studio's UI?
This seems like an obvious thing to be able to do, but after searching MSDN and Google for quite a while, I'm stumped. The closest thing I found was Provider Statistics for SQL Server (ADO.NET) on MSDN, but those stats seem to be client-side stats about network connectivity (e.g. bytes sent/received) from the client's perspective, not the server-side statistics I'm looking for.
See the answer to this question.
The statistics info is just stored in the messages tab.
If you use
SET STATISTICS...
with this method you should be able to get what you are after.