How to determine query statistics from client ? | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

How to determine query statistics from client ?

Hello, I would like to get query statistics after sending query to SQL Server. (physical and logical reads of the last executed query). Is there any way to do this ? I’m using C# within ODBC if that’s important.

You mean something like you get with SET STATISTICS IO ON?

Frank Kalis
SQL Server MVP
http://www.insidesql.de

Yes, exactly that information.
I might be wrong on this, but I think this output is only informational and can only be seen from within SQL Server. I’ve googled a bit on this, but couldn’t find any solution, so I don’t think you can retrieve it any way. You might be able to get this numbers using @@TOTAL_READ and @@TOTAL_WRITE global system variables, but that approach seem to be a kludge at best and prone to errors to me. —
Frank Kalis
SQL Server MVP
http://www.insidesql.de

Thank you for your efforts. I am trying now with the system table "sysperfinfo" that is the representation of the internal performance counters.
This won’t go down to show the values for a single given query, but in this context might it be interesting to google for sp_user_counter.

Frank Kalis
SQL Server MVP
http://www.insidesql.de

I think the output for IO is sent to query analyser as a PRINT rather than a result set. It should be possible to retrieve this if youre using ADO. I dont recall the exact property but look into the Errors or ErrorList collection of the ADO resultset obejct
]]>