使用 C# 运行 Sql Agent 作业的最佳方法是什么? [英] what is the best way to run Sql Agent job using C#?

查看:34
本文介绍了使用 C# 运行 Sql Agent 作业的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Sql server 2005 并使用 C#/Asp.Net 4.0 作为 UI.我想从网页中的用户操作触发 sql 作业.我需要在作业运行时不断检查作业的状态.关于这个问题有几个旧线程可以获取作业的状态(如何在 C# 中监视 SQL Server 代理作业信息) 但我需要我的程序应该能够运行、停止、启用、禁用作业

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. 检查 sql 作业的状态

  1. Check the status of a sql job

运行指定的作业

停止工作

禁用/启用作业

推荐答案

您可以使用以下系统存储过程:

You can use the following system stored procedures:

sp_start_job - 启动一个代理工作
sp_stop_job - 停止代理作业
sp_update_job - 启用/禁用代理工作

sp_start_job - start an Agent job
sp_stop_job - stop an Agent job
sp_update_job - enable/disable an Agent job

更新:如果您真的想改用 SMO,最好的检查地点是 此 MSDN 参考.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.

这篇关于使用 C# 运行 Sql Agent 作业的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆