可以通过点击按钮在ASP.Net页面中从SQL Server Agent执行Job强>?
最佳答案
您可以使用 sp_start_job (Transact-SQL)
Instructs SQL Server Agent to execute a job immediately.
[ @job_name= ] 'job_name'
The name of the job to start. Either job_id or job_name must be specified, but both cannot be specified. job_name is sysname, with a default of NULL.
您可以将它用作存储过程而不是在您的代码中运行它。
如果您的作业运行 dts 包,您可以使用 Package.Execute method
Returns a DTSExecResult enumeration that contains information about the success or failure of the package execution.
示例来自 MSDN 页面;
static void Main(string[] args)
{
Package p = new Package();
p.InteractiveMode = true;
p.OfflineMode = true;
// Add a Script Task to the package.
TaskHost taskH = (TaskHost)p.Executables.Add(typeof(Microsoft.SqlServer.Dts.Tasks.ScriptTask.ScriptTask).AssemblyQualifiedName);
// Run the package.
p.Execute();
// Review the results of the run.
if (taskH.ExecutionResult == DTSExecResult.Failure || taskH.ExecutionStatus == DTSExecStatus.Abend)
Console.WriteLine("Task failed or abended");
else
Console.WriteLine("Task ran successfully");
}
关于c# - 如何从 SQL Server 代理运行作业?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20393714/