Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get parameter values for SQL Server query in SQL Server Profiler

I'm trying to analyze a deadlock in SQL Server 2008 profiler. I know how to find the offending sql queries, but the collected queries do not include parameter values.

I other words I can see something like this:

DELETE FROM users WHERE id = @id

But what I would like to see is this:

DELETE FROM users WHERE id = 12345

I guess there are some additional events or Columns I need to collect in the profiler, but I don't know which. I am currently using the "TSQL_LOCKS" template.

Any hints would be greatly appreciated.

Thanks,

Adrian

Disclaimer: I've asked a similar question before, but I guess it was too specific, which is why I got no replies. I'm starting another attempt with this one.

like image 624
Adrian Grigore Avatar asked Dec 23 '09 13:12

Adrian Grigore


People also ask

How do I run a parameter query in SQL Server?

First, declare two variables, @table for holding the name of the table from which you want to query and @sql for holding the dynamic SQL. Second, set the value of the @table variable to production. products . Fourth, call the sp_executesql stored procedure by passing the @sql parameter.


2 Answers

I think you need the RPC:Completed event:

http://msdn.microsoft.com/en-us/library/ms175543.aspx

like image 105
davek Avatar answered Oct 31 '22 02:10

davek


The Profiler will contain the parameter values in the RPC:Completed/RPC:Starting events. But you already got replies telling you this.

What I want to add is that is very little need to know the parameter run-time values in order to analyze a deadlock graph. First, because if 'users' is involved in the deadlock, the deadlock graph itself will give away what @id is the conflict, if the conflict is on a key. Second, more importantly, for a deadlock scenario is irrelevant the exact keys that are involved. Is not like a deadlock happens because one deletes user with id 123 but will not happen when it deletes user 321.

If you decided to ask on SO in the first place, I think the best would be to post the actual deadlock graph and let the community have a look at it. There are many here that can answer quite a few questions just from the deadlock graph XML.

like image 45
Remus Rusanu Avatar answered Oct 31 '22 02:10

Remus Rusanu