问题
I am using Sql server 2005 and using C#/Asp.Net 4.0 for UI. I want to trigger the sql job from an user action in a webpage. I need to keep checking job's status while its running. There are several old threads on this issue which gets the status of the jobs (How to monitor SQL Server Agent Job info in C#) but i need my program should be able to Run,Stop,Enable,Disable the jobs
I need the below functionality in my UI.
Check the status of a sql job
Run the specified job
Stop the job
Disable/Enable the job
回答1:
You can use the following system stored procedures:
sp_start_job - start an Agent job
sp_stop_job - stop an Agent job
sp_update_job - enable/disable an Agent job
Update: If you really want to use SMO instead, best place to check out is this MSDN reference. The Job class allows you to do all this.
来源:https://stackoverflow.com/questions/10173957/what-is-the-best-way-to-run-sql-agent-job-using-c