我想安排一组每周运行/可配置的查询。我通过googling在代码下面找到,但我正在尝试设置每周执行的sheduler时间。我也希望它是可配置的。我对此非常陌生,所以somw帮助将不胜感激!
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();
提供作业调度程序示例的链接。在找到如何设置计划时间时丢失了!
答案 0 :(得分:1)
您在代码中使用的FrequencyTypes Enum应具有“每周”值。