문제

I am using C#, SQL Server 2008 and SQL Management Objects, and I need to know if there is a way to get the current executing Stored Procedure(s) using SMO/C#. I have some long-running Stored Procedures and I need to monitor their current status by determining whether they are idle or executing. Can this be done with SMO? If so, how?

도움이 되었습니까?

해결책

You might be able to back into it with the EnumProccesses method on the Server object. I really feel like this is a case of "when you have a hammer, everything looks like a nail", though. That is, you'll be able to do a lot better with raw T-SQL against system views like sys.dm_exec_requests

다른 팁

I agree with Ben Thul, the following SQL statement from here should do the job (though I haven't tested it):

SELECT  requests.session_id, 
    requests.status, 
    requests.command, 
    requests.statement_start_offset,
    requests.statement_end_offset,
    requests.total_elapsed_time,
    details.text
FROM    sys.dm_exec_requests requests
CROSS APPLY sys.dm_exec_sql_text (requests.plan_handle) details
WHERE   requests.session_id > 50
ORDER BY total_elapsed_time DESC
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top