c# - 如何从 SQL Server 代理运行作业?

标签 c# asp.net sql-server-2008

可以通过点击按钮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/

相关文章:

c# - 无法在 SQL Server 2008 中创建序列

c# - 做一个asp :TextBox inside a Repeater fire the Repeater's ItemCommand when Enter pressed

c# - 除非断言失败,否则不构建上下文消息来加速单元测试

c# - 具有相同名称的多个单选按钮需要架构

c# - 包装 API 以支持依赖注入(inject)

javascript - 智能表格排序不起作用

c# - 在 Rider 和 Visual Studio 中使用 C# 和 ASP.Net 的 Git 问题

php - 根据主键表的主键获取外键表的行数

SQL Server 舍入问题,其中有 5

sql - 如何在 SQL Server 中有效地合并两个层次结构?