Export (0) Print
Expand All

Job.OwnerLoginName Property

Gets or sets the owner of the job.

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

[SfcPropertyAttribute(SfcPropertyFlags.Standalone)]
public string OwnerLoginName { get; set; }

Property Value

Type: System.String
A String value that specifies the logon name of the job owner.

Microsoft SQL Server establishes ownership rules for jobs. Some permissions default to a job owner, and ownership forms one part of SQL Server access control.

Set the OwnerLoginName property to change ownership for the referenced job. The value must specify an existing SQL Server database user. Permission to change job ownership defaults to members of the sysadmin group.

The following code example creates a job and gives ownership of the job to a different login.

C#

Server srv = new Server("(local)");
Job jb = new Job(srv.JobServer, "Test Job");
jb.Create();
jb.OwnerLoginName = "OperatorName"

PowerShell

$srv = new-object Microsoft.SqlServer.Management.Smo.Server("(local)")
$jb = new-object Microsoft.SqlServer.Management.Smo.Agent.Job($srv.JobServer, "Test Job")
$jb.Create()
$jb.OwnerLoginName = "OperatorName"

Community Additions

ADD
Show:
© 2015 Microsoft