0

我想安排一组查询每周运行/可配置。我通过谷歌搜索找到了下面的代码,但我现在正在尝试设置每周执行的调度程序时间。我也希望它是可配置的。我对此很陌生,因此将不胜感激!

 Server server = new Server(".");

        // Get instance of SQL Agent SMO object 
        JobServer jobServer = server.JobServer;
        Job job = null;
        JobStep step = null;
        JobSchedule schedule = null;

        // Create a schedule 
        schedule = new JobSchedule(jobServer, "Schedule_1");
        schedule.FrequencyTypes = FrequencyTypes.OneTime;
        schedule.ActiveStartDate = DateTime.Today;
        //schedule.ActiveStartTimeOfDay = new TimeSpan(DateTime.Now.Hour, (DateTime.Now.Minute + 2), 0);
        schedule.Create();

        // Create Job 
        job = new Job(jobServer, "Job_1");
        job.Create();
        job.AddSharedSchedule(schedule.ID);
        job.ApplyToTargetServer(server.Name);
        job.

        // Create JobStep 
        step = new JobStep(job, "Step_1");
        step.Command = "SELECT 1";
        step.SubSystem = AgentSubSystem.TransactSql;

        step.Create();

提供作业调度程序示例的链接。我迷失了如何设置调度时间!

4

1 回答 1

1

您在代码中使用的 FrequencyTypes Enum 应该有一个 Weekly 值。

http://technet.microsoft.com/en-us/library/microsoft.sqlserver.management.smo.agent.frequencytypes.aspx

于 2013-12-07T14:21:42.757 回答