首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用C#调度SSIS包

使用C#调度SSIS包
EN

Stack Overflow用户
提问于 2012-03-04 18:01:14
回答 1查看 1.4K关注 0票数 2

我想做的是,使用C#调度一个SSIS包。缺少的部分是,如何告诉代理这个调度是针对SSIS包"X“的,下面是我的代码:

代码语言:javascript
复制
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();

耽误您时间,实在对不起。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-03-05 05:55:10

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

毫无疑问,您还需要查看dtexec以了解如何配置和调用您的包,或者您可以像我一样作弊,使用dtexecui或代理构建SET和其他命令,然后将它们粘贴为源命令。

代码语言:javascript
复制
        //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();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9553953

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档