Monday, October 17, 2011

SQL Server: Using SQL Profiler to Capture Stored Procedure Call from Application


SQL Profiler is a high-quality tool to figure out different database issues, like “Which are costliest queries running”, “Which quires acquired exclusive locks”, “Which indexes are missing” and so on. But in development environment and on production when solving a problem, developers like to use SQL Profiler to get exact procedure call which is being generated by front end application.
Worst practice is, that developers like to use existing built in templates for this purpose and normally use default one i.e. STANDARD.  If you are also using SQL Profiler for this procedure call purpose, then selecting STANDARD trace template is not a good choice, as on production server it affects its performance and even on development server it returns much more extra information.
Good practice is, if you have not created your own template then always select TUNING.


 It also has some extra information so when you only need to catch procedure calls generated from your application then click on “Event Selection” tab and keep only “RPC:Completed” event. You need not to select “Sp: stmt Completed” as you just need to capture “execute procedure calls” and not all the statement inside this procedure. You can also omit “SP: Batch Completed” as we need calls that are only generated from application. If you also need to capture calls from SSMS then you can keep it.


To avoid extra work pressure on server and to get your required results only, you must also apply filters on “Database Name” and “Text

 Use % sign, just like you use in LIKE operator.

Now run your trace and you will find your required results quickly and clearly, even without putting extra work load on database server.

19 comments:

  1. Excellent - That works perfectly - Simple!

    ReplyDelete
  2. awesome work man ... works like a charm

    ReplyDelete
  3. Great post!

    Regards,
    UHM

    ReplyDelete
  4. Yes,,Great ,,this article helped a lot !

    ReplyDelete
  5. Very simple and that's what's needed most of the time.

    Very good, thanks Aasim!!!

    ReplyDelete
  6. Once I get Profiler set up Ill have a go at this. So basically you just put your SP name as a filter for Test Data %USP_Fact_Table%
    ?

    ReplyDelete
    Replies
    1. You can do this filter on ObjectName, if you have selected from columns list, but as per my example, we have not selected ObjectName column so in this case you can put filter on TextData column like you said %USP_Fact_Table%

      Delete
  7. Very straight forward way to trace a stored procedure. I like this.

    ReplyDelete
  8. Simple But Excellent Post.......Thanks

    ReplyDelete
  9. Really fantastic thanks.....

    ReplyDelete
  10. Can i use Sql server standard version sp1 for SQL Profiler. because it is not showing all option like..i want to figure out deadlock..So please can any one explain .?

    ReplyDelete
  11. clear explanation, great post.

    ReplyDelete
  12. works great. Thanks.

    ReplyDelete
  13. How would I retrieve the Stored procedures name all that I read is sp_executesql N

    ReplyDelete
  14. Thank you - exactly what I needed !!! Works like a charm in SQL 2012

    ReplyDelete

All suggestions are welcome