【问题标题】:Schedule SSIS Package using C#使用 C# 计划 SSIS 包
【发布时间】:2012-03-04 10:01:14
【问题描述】:

我想做的是使用 C# 安排一个 SSIS 包。缺少的部分是,如何告诉代理这个时间表是针对 SSIS 包“X”的,这是我的代码:

Server srv = new Server();

//Define an Operator object variable by supplying the Agent (parent JobServer object) and the name in the constructor. 
Operator op = new Operator(srv.JobServer, "AC_Operator") { NetSendAddress = "Network1_PC" };

//Create the operator on the instance of SQL Server Agent. 
op.Create();

//Define a Job object variable by supplying the Agent and the name arguments in the constructor and setting properties. 
Job jb = new Job(srv.JobServer, "AC_Job");

//Specify which operator to inform and the completion action. 
jb.OperatorToNetSend = "AC_Operator";
jb.NetSendLevel = CompletionAction.Always;

//Create the job on the instance of SQL Server Agent. 
jb.Create();

//Define a JobStep object variable by supplying the parent job and name arguments in the constructor. 
JobStep jbstp = new JobStep(jb, "AC_Job_Step");
jbstp.OnSuccessAction = StepCompletionAction.QuitWithSuccess;
jbstp.OnFailAction = StepCompletionAction.QuitWithFailure;

//Create the job step on the instance of SQL Agent. 
jbstp.Create();

//Define a JobSchedule object variable by supplying the parent job and name arguments in the constructor. 

JobSchedule jbsch = new JobSchedule(jb, "AC_Job_Schedule");

//Set properties to define the schedule frequency, and duration. 
jbsch.FrequencyTypes = FrequencyTypes.Daily;
jbsch.FrequencySubDayTypes = FrequencySubDayTypes.Minute;
jbsch.FrequencySubDayInterval = 30;
TimeSpan ts1 = new TimeSpan(9, 0, 0);
jbsch.ActiveStartTimeOfDay = ts1;

TimeSpan ts2 = new TimeSpan(17, 0, 0);
jbsch.ActiveEndTimeOfDay = ts2;
jbsch.FrequencyInterval = 1;

DateTime d = new DateTime(2003, 1, 1);
jbsch.ActiveStartDate = d;

//Create the job schedule on the instance of SQL Agent. 
jbsch.Create();

感谢您的宝贵时间。

【问题讨论】:

  • 您需要将jbstp 配置为 SSIS 类型,然后您应该能够指定详细信息(名称、配置文件等)
  • 是的,我想到了,但我不知道该怎么做!任何细节?谢谢。

标签: c# ssis sql-server-2008-r2 scheduled-tasks


【解决方案1】:

您需要做的是设置作业步骤的SubSystem,然后构建您的Command。在将 .NET 生成的代码与 SQL 代理创建的作业进行比较时,我注意到的唯一区别是 DatabaseName 属性的分配,所以我也设置了它。

您无疑还想查看dtexec 以了解如何配置和调用您的包,或者您可以像我一样作弊并使用 dtexecui 或代理来构建 SET 和其他命令,然后粘贴这些in 作为源命令。

        //Define a JobStep object variable by supplying the parent job and name arguments in the constructor. 
        JobStep jbstp = new JobStep(jb, "AC_Job_Step");
        jbstp.OnSuccessAction = StepCompletionAction.QuitWithSuccess;
        jbstp.OnFailAction = StepCompletionAction.QuitWithFailure;

        string command = string.Empty;
        command = @"/FILE ""C:\sandbox\SSISHackAndSlash2008\SSISHackAndSlash2008\EzAPI_Recipe01.dtsx""  /CHECKPOINTING OFF /REPORTING E";
        jbstp.SubSystem = AgentSubSystem.Ssis;
        jbstp.DatabaseName = "master";
        jbstp.Command = command;

        //Create the job step on the instance of SQL Agent. 
        jbstp.Create();

【讨论】:

  • 谢谢你,你很有帮助^^
猜你喜欢
  • 2016-07-30
  • 2022-01-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多