views:

28

answers:

2

I'd like to do something similar to http://stackoverflow.com/questions/2116960/queries-count-for-page-in-asp-net-mvc - namely count the number of SQL queries executed in a particular request, and time them.

The difference is, I don't have a standard method that all SQL queries are routed through - I need a method for intercepting all calls and tracking them. Is there some kind of hook I could use, or do you know of a tutorial for using the .NET profiler to record calls to and from a method, or even another method?

I don't want to use the SQL Server profiler library for this - I want something built into .NET so there are no dependencies. THanks!

A: 

You can use PostSharp for this.

RedFilter
I'm fairly familiar with PostSharp but wouldn't really know where to start when it comes to intercepting calls to the BCL. Do you have any more pointers?
mcintyre321
I am assuming you would trace your own methods that are calling BCL.
RedFilter
I would like to be able to trace other peoples methods too! I guess the CLR Profiler API would be the way to go...
mcintyre321
A: 

The latest version of ANTS Performance Profiler allows you to use Event Tracing for Windows to pick up the SQL Queries as well. You may be able to automate this, but I'm not sure.

Mel Harbour