是否可以通过单击 按钮 在 ASP.Net 页面中触发从 SQL Server Agent 执行 作业?
是否可以通过单击 按钮 在 ASP.Net 页面中触发从 SQL Server Agent 执行 作业?
sp_start_job (Transact-SQL)
命令立即执行作业。Package.Execute method
命令。 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");
}
sp_start_job
返回0(成功)或1(失败)。请查看文档。如果您发现这些答案有用,请不要忘记点赞并接受其中之一。 - Soner Gönül是的,这是可能的。您也可以使用
Server server = new Server("<replace_with_your_server>");
server.JobServer.Jobs["<replace_with_your_job_name>"]?.Start();