In my last post on sp_who2 I demonstrated how this handy utility can help you in your SQL Server troubleshooting efforts.
Continuing on from this, I am going to cover DBCC INPUTBUFFER
What is DBCC INPUTBUFFER ?
It is a command used to identify the last statement executed by a particular SPID. You would typically use this after running sp_who2. The great thing about this DBCC command is that it shows the last statement executed, whether running or finished.
How to use
DBCC INPUT BUFFER will generate errors so ensure that the space between INPUT and BUFFER is omitted.
In this example, I have just run run sp_who2 and identified that my lead blocker is SPID number 54 so I would run as follows:
[sourcecode language=’sql’]DBCC INPUTBUFFER(54)[/sourcecode]
Here is a simple demonstration. In a new query window run this
UPDATE Orders SET Amount = 500 WHERE OrderID = 1;[/sourcecode]
Now in a second query window run this
[sourcecode language=’sql’]UPDATE Orders SET Amount = 200 WHERE OrderID = 1;[/sourcecode]
Now run sp_who2 to identify the lead blocker followed by DBCC INPUTBUFFER using the lead blocker SPID. Here are my results with the column “EventInfo” providing the detail that I need on the T-SQL which is causing the problem. It is possible to copy and paste the code into a query window for analysis.
Permissions needed for DBCC INPUTBUFFER
You need to be a sysadmin or have the VIEW SERVER STATE permission to be able to run this command.
Again, like sp_who2, this handy command should be in your “DBA Toolbox”.
Leave a Reply