Schedule Object

SQL-DMO

SQL-DMO
Methods
BeginAlter Method DoAlter Method
CancelAlter Method Refresh Method

Remarks

SQL Server Agent automates administration and replication tasks. Any task automated by the SQL Server Agent can be scheduled for one-time or repeated execution. The timetable for repeated execution can be elaborate, specifying that the task execute monthly on a given day of a given week, weekly on one or more days, or every minute of every day.

With the Schedule object, you can:

  • Set or adjust the execution timetable for a SQL Server Agent job schedule.

  • Set or adjust the execution timetable for SQL Server replication article publication and pull subscriptions.

To schedule one-time execution of a SQL Server executable task

  1. Get the Schedule object required from the appropriate object referencing the task. For example, to adjust a SQL Server Agent job schedule, get the Schedule object from the JobSchedule object that references the SQL Server Agent job schedule.

  2. Use the BeginAlter method of the Schedule object to mark the start of changes to the timetable.

  3. Set the ActiveStartDate property to the date you want the task to execute. The date properties of a Schedule object pack a date string into a long integer value as the year, scaled by 10,000, plus the month, scaled by 100, plus the day. For example, December 1, 1997 is represented by the integer 19971201.

  4. Set the ActiveStartTimeOfDay property to the time you want the task to execute.

  5. Set the ActiveEndDate and ActiveEndTimeOfDay properties to a day and time later than the day and time you want the task to execute.

  6. Set the FrequencyType property to SQLDMOFreq_OneTime.

  7. Use the DoAlter method to mark the end of changes to the Schedule object and submit those changes to SQL Server.

To schedule a SQL Server executable task for weekly execution on specified days

  1. Get the Schedule object required from the appropriate object referencing the task.

  2. Use the BeginAlter method of the Schedule object to mark the start of changes to the timetable.

  3. Set the ActiveStartDate and ActiveEndDate properties to the dates you want the timetable to become effective and no longer effective.

  4. Set the ActiveStartTimeOfDay property to the time you want SQL Server Agent to execute the task.

  5. Set the ActiveEndTimeOfDay property to a time greater than the start time for the task.

  6. Set the FrequencyType property to SQLDMOFreq_Weekly.

  7. Set the FrequencyInterval property to the days the task should run. The value can be specified as a single-day constant or a binary OR of day constants. For example, to set the property for weekly execution of the task on Sunday, use the constant SQLDMOWeek_Sunday. To specify Monday, Wednesday, and Friday, use a binary OR of the constants SQLDMOWeek_Monday, SQLDMOWeek_Wednesday, and SQLDMOWeek_Friday.

  8. Use the DoAlter method to mark the end of changes to the Schedule object and submit the changes to SQL Server.