Database.Grant Database.Grant Database.Grant Method

Definition

Grants the specified set of permissions to the specified grantees on the database.

Overloads

Grant(DatabasePermissionSet, String, Boolean, String) Grant(DatabasePermissionSet, String, Boolean, String) Grant(DatabasePermissionSet, String, Boolean, String)

Grants the specified set of permissions to the grantee and the ability to grant the set of permissions to other users on the database under an assumed role.

Grant(DatabasePermissionSet, String[], Boolean) Grant(DatabasePermissionSet, String[], Boolean) Grant(DatabasePermissionSet, String[], Boolean)

Grants access to the specified permission to the grantees and the ability to grant access to other users on the database.

Grant(DatabasePermissionSet, String[], Boolean, String) Grant(DatabasePermissionSet, String[], Boolean, String) Grant(DatabasePermissionSet, String[], Boolean, String)

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the database under an assumed role.

Grant(DatabasePermissionSet, String[]) Grant(DatabasePermissionSet, String[]) Grant(DatabasePermissionSet, String[])

Grants the specified set of permissions to the specified grantees on the database.

Grant(DatabasePermissionSet, String) Grant(DatabasePermissionSet, String) Grant(DatabasePermissionSet, String)

Grants the specified set of permissions to the specified grantee on the database.

Grant(DatabasePermissionSet, String, Boolean) Grant(DatabasePermissionSet, String, Boolean) Grant(DatabasePermissionSet, String, Boolean)

Grants access to the specified permission to the grantee and the ability to grant access to other users on the database.

Grant(DatabasePermissionSet, String, Boolean, String) Grant(DatabasePermissionSet, String, Boolean, String) Grant(DatabasePermissionSet, String, Boolean, String)

Grants the specified set of permissions to the grantee and the ability to grant the set of permissions to other users on the database under an assumed role.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::DatabasePermissionSet ^ permission, System::String ^ granteeName, bool grantGrant, System::String ^ asRole);
public void Grant (Microsoft.SqlServer.Management.Smo.DatabasePermissionSet permission, string granteeName, bool grantGrant, string asRole);
Public Sub Grant (permission As DatabasePermissionSet, granteeName As String, grantGrant As Boolean, asRole As String)
Parameters
permission
DatabasePermissionSet DatabasePermissionSet DatabasePermissionSet

A DatabasePermissionSet object value that specifies the set of permissions.

granteeName
String String String

A String value that specifies a grantee to be denied access to the permission.

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the specified set of permissions to other users on the database.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the database.

If False, the grantee is not given the ability to grant the specified set of permissions to other users on the database.

asRole
String String String

A String value that specifies the role that the user assumes when that user grants the specified set of permissions to other users on the database. Use this parameter for grantees who are members of more than one role.

Examples

The example shows how to use the Grant method with server permissions. The method is the same for database permissions.

VB

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(DatabasePermissionSet, String[], Boolean) Grant(DatabasePermissionSet, String[], Boolean) Grant(DatabasePermissionSet, String[], Boolean)

Grants access to the specified permission to the grantees and the ability to grant access to other users on the database.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::DatabasePermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames, bool grantGrant);
public void Grant (Microsoft.SqlServer.Management.Smo.DatabasePermissionSet permission, string[] granteeNames, bool grantGrant);
Public Sub Grant (permission As DatabasePermissionSet, granteeNames As String(), grantGrant As Boolean)
Parameters
permission
DatabasePermissionSet DatabasePermissionSet DatabasePermissionSet

A DatabasePermissionSet object value that specifies the set of permissions.

granteeNames
String[]

A String array that specifies a list of grantees to be denied access to the set of permissions.

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the specified set of permissions to other users on the database.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the database.

If False, the grantee is not given the ability to grant the specified set of permissions to other users on the database.

Examples

The example shows how to use the [Grant Method (DatabasePermissionSet, String<xref:Microsoft.SqlServer.Management.Smo.Database.Grant%2A> method with server permissions. The method is the same for database permissions.

VB

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(DatabasePermissionSet, String[], Boolean, String) Grant(DatabasePermissionSet, String[], Boolean, String) Grant(DatabasePermissionSet, String[], Boolean, String)

Grants the specified set of permissions to the grantees and the ability to grant the set of permissions to other users on the database under an assumed role.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::DatabasePermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames, bool grantGrant, System::String ^ asRole);
public void Grant (Microsoft.SqlServer.Management.Smo.DatabasePermissionSet permission, string[] granteeNames, bool grantGrant, string asRole);
Public Sub Grant (permission As DatabasePermissionSet, granteeNames As String(), grantGrant As Boolean, asRole As String)
Parameters
permission
DatabasePermissionSet DatabasePermissionSet DatabasePermissionSet

A DatabasePermissionSet object value that specifies the set of permissions.

granteeNames
String[]

A String array that specifies a list of grantees to be granted the set of permissions.

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the set of permissions to other users on the database.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the database.

If False, the grantee is not given the ability to grant the specified set of permissions to other users on the database.

asRole
String String String

A String value that specifies the role that the user assumes when that user grants the specified set of permissions to other users on the database. Use this parameter for grantees who are members of more than one role.

Examples

The example shows how to use the [Grant Method (DatabasePermissionSet, String<xref:Microsoft.SqlServer.Management.Smo.Database.Grant%2A> method with server permissions. The method is the same for database permissions.

VB

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(DatabasePermissionSet, String[]) Grant(DatabasePermissionSet, String[]) Grant(DatabasePermissionSet, String[])

Grants the specified set of permissions to the specified grantees on the database.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::DatabasePermissionSet ^ permission, cli::array <System::String ^> ^ granteeNames);
public void Grant (Microsoft.SqlServer.Management.Smo.DatabasePermissionSet permission, string[] granteeNames);
Public Sub Grant (permission As DatabasePermissionSet, granteeNames As String())
Parameters
permission
DatabasePermissionSet DatabasePermissionSet DatabasePermissionSet

A DatabasePermissionSet object value that specifies the set of permissions.

granteeNames
String[]

A String array that lists the grantees to be granted the specified set of permissions on the database.

Examples

The example shows how to use the Grant method with server permissions. The method is the same for database permissions.

VB

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(DatabasePermissionSet, String) Grant(DatabasePermissionSet, String) Grant(DatabasePermissionSet, String)

Grants the specified set of permissions to the specified grantee on the database.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::DatabasePermissionSet ^ permission, System::String ^ granteeName);
public void Grant (Microsoft.SqlServer.Management.Smo.DatabasePermissionSet permission, string granteeName);
Public Sub Grant (permission As DatabasePermissionSet, granteeName As String)
Parameters
permission
DatabasePermissionSet DatabasePermissionSet DatabasePermissionSet

A DatabasePermissionSet object value that specifies the set of permissions.

granteeName
String String String

A String value that specifies the grantee to be granted the specified set of permissions on the database.

Examples

The example shows how to use the Grant method with server permissions. The method is the same for database permissions.

VB

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Grant(DatabasePermissionSet, String, Boolean) Grant(DatabasePermissionSet, String, Boolean) Grant(DatabasePermissionSet, String, Boolean)

Grants access to the specified permission to the grantee and the ability to grant access to other users on the database.

public:
 void Grant(Microsoft::SqlServer::Management::Smo::DatabasePermissionSet ^ permission, System::String ^ granteeName, bool grantGrant);
public void Grant (Microsoft.SqlServer.Management.Smo.DatabasePermissionSet permission, string granteeName, bool grantGrant);
Public Sub Grant (permission As DatabasePermissionSet, granteeName As String, grantGrant As Boolean)
Parameters
permission
DatabasePermissionSet DatabasePermissionSet DatabasePermissionSet

A DatabasePermissionSet object value that specifies the set of permissions.

granteeName
String String String

A String value that specifies the grantee to be denied specified set of permissions.

grantGrant
Boolean Boolean Boolean

A Boolean property that specifies whether the grantee is given the ability to grant the set of permissions to other users on the database.

If True, the grantee is given the ability to grant the specified set of permissions to other users on the database.

If False, the grantee is not given the ability to grant the specified set of permissions to other users on the database.

Examples

The example shows how to use the Grant method with server permissions. The method is the same for database permissions.

VB

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$arg = [Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint  

$sps = new-object Microsoft.SqlServer.Management.Smo.ServerPermissionSet([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  
$sps.Add([Microsoft.SqlServer.Management.Smo.ServerPermission]::AlterAnyEndpoint)  
$spis = $srv.EnumServerPermissions("vGrantee", $sps)  
Write-Host "=================Before revoke==========================="  
Foreach ($spi In $spis)  
{  
   Write-Host $spi.Grantee "has" $spi.PermissionType " permission."  
}  
Write-Host " "  
$sps.Remove([Microsoft.SqlServer.Management.Smo.ServerPermission]::CreateEndpoint)  

Applies to