what is the best way to run Sql Agent job using C#?

僤鯓⒐⒋嵵緔 提交于 2020-01-03 04:47:29

问题


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.

  1. Check the status of a sql job

  2. Run the specified job

  3. Stop the job

  4. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!