Question

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?

Était-ce utile?

La solution

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

Autres conseils

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
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top