Condividi tramite


JobSchedules Collection

Questa caratteristica verrà rimossa a partire da una delle prossime versioni di Microsoft SQL Server. Evitare di utilizzare questa funzionalità in un nuovo progetto di sviluppo e prevedere interventi di modifica nelle applicazioni in cui è attualmente implementata.

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

Modello di oggetti SQL-DMO in cui è visualizzato l'oggetto corrente

Properties

Osservazioni

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)

[!NOTA]

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.