Share via


Job.AddSharedSchedule Method

Adds a shared schedule to the Microsoft SQL Server Agent job.

Namespace:  Microsoft.SqlServer.Management.Smo.Agent
Assembly:  Microsoft.SqlServer.Smo (in Microsoft.SqlServer.Smo.dll)

Syntax

'Declaration
Public Sub AddSharedSchedule ( _
    scheduleId As Integer _
)
'Usage
Dim instance As Job 
Dim scheduleId As Integer

instance.AddSharedSchedule(scheduleId)
public void AddSharedSchedule(
    int scheduleId
)
public:
void AddSharedSchedule(
    int scheduleId
)
member AddSharedSchedule : 
        scheduleId:int -> unit
public function AddSharedSchedule(
    scheduleId : int
)

Parameters

  • scheduleId
    Type: System.Int32
    An Int32 value that specifies the ID value that uniquely identifies the shared schedule.

Examples

The following code example creates a job schedule and shares it between two jobs.

C#

Server srv = new Server("(local)");
Job jb = new Job(srv.JobServer, "Test Job");
Job jb2 = new Job(srv.JobServer, "Second Test Job");
jb.Create();
jb2.Create();
JobSchedule jbsch = new JobSchedule(jb, "Test Job Schedule");
jbsch.Create();
jb2.AddSharedSchedule(jbsch.ID);

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")
$jb = new-object Microsoft.SqlServer.Management.Smo.Agent.Job($srv.JobServer, "Test Job")
$jb2 = new-object Microsoft.SqlServer.Management.Smo.Agent.Job($srv.JobServer, "Second Test Job")
$jb.Create()
$jb2.Create()
$jbsch = new-object Microsoft.SqlServer.Management.Smo.Agent.JobSchedule($jb, "Test Job Schedule")
$jbsch.Create()
$jb2.AddSharedSchedule($jbsch.ID)

See Also

Reference

Job Class

Microsoft.SqlServer.Management.Smo.Agent Namespace

Other Resources

Automated Administration Tasks (SQL Server Agent)

Scheduling Automatic Administrative Tasks in SQL Server Agent

sp_add_schedule (Transact-SQL)