Partager via


JobSchedules Collection

Cette fonctionnalité sera supprimée dans une prochaine version de Microsoft SQL Server. Évitez d'utiliser cette fonctionnalité dans de nouveaux travaux de développement et prévoyez de modifier les applications qui utilisent actuellement cette fonctionnalité.

The JobSchedules collection contains JobSchedule objects, each referencing one execution schedule for a SQL Server Agent job.

Modèle objet SQL-DMO qui affiche l'objet en cours

Properties

Notes

A SQL Server Agent job defines an administrative task. A job may or may not be scheduled. When scheduled, SQL Server Agent evaluates the schedule or schedules associated with the job and attempts automated execution of the job at the time(s) defined by the schedule(s). When not scheduled, a job may be executed on demand by a properly authorized user.

When a SQL Server Agent job is scheduled, the JobSchedules collection of the Job object that references the job contains one or more JobSchedule objects. Use the Count property to determine the number of schedules established for the job. When the Count property of a JobSchedules collection returns 0, the job has no automated execution schedule. Use the Start method of the Job object to execute the referenced job.

With the JobSchedules collection, you can:

  • Define an execution schedule for a SQL Server Agent job.

  • Stop automated execution of a SQL Server Agent job by removing an execution schedule.

For more information about scheduling job execution by adding a JobSchedule to the JobSchedules collection, see the JobSchedule Object section.

To stop automated execution of a SQL Server Agent job

  • Use the Remove method of the JobSchedules collection, as in:

    oJob.JobSchedules.Remove("Northwind_Hourly_Log_Backup")
    

When using the Item or Remove method, the JobSchedules collection supports member identification using either name or ordinal reference syntax. For example:

Set oJobSchedule = oJob.JobSchedules("Northwind_Backup_DB")

Or

Set oJobSchedule = oJob.JobSchedules(1)

[!REMARQUE]

Scheduling automated execution of SQL Server Agent jobs using the JobSchedules collection requires appropriate privilege. The Microsoft® SQL Server™ login used for SQLServer object connection must be a member of the fixed role public in the system database msdb. With public membership, the connection may schedule jobs belonging to the connected login. Members of the db_owner role in msdb, or members of a role with greater privilege, can schedule any SQL Server Agent job.