Storeced procedure hangs

Once in a while the stored procedure hangs, How can I find which statement from stored procedure is timing out or making the SQL hang while process is hang.

sp_who2  can find the process ID but Is there any way I can find which statement within the stored procedure makes whole stored procedure hangs?
Bharat GuruAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
You can pass the spid to DBCC INPUTBUFFER (<spid>)

alternatively , you can get the SQLHandle, passing the spId to the below statement
SELECT SQL_HANDLE  
FROM MASTER..SYSPROCESSES  
WHERE SPID = @SPID    
 -- and run this statement using that sqlhandle
SELECT [TEXT] FROM ::FN_GET_SQL(@SQLHandle)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HugoHiaslCommented:
Another way is to use PRINT('text')  statements and run the stored procedure in SQL Management studio. In the "Messages" tab you can see what PRINT statement was executed last when it hangs.
0
Vitor MontalvãoMSSQL Senior EngineerCommented:
Start a SQL Profiler just before you run the SP again and capture and single SQL Statements. You'll see which one is originating the issue.
0
Bharat GuruAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.