Database.ApplicationRoles Database.ApplicationRoles Database.ApplicationRoles Property

Definition

Gets a collection of ApplicationRole objects. Each ApplicationRole object represents an application role defined on the database.

public:
 property Microsoft::SqlServer::Management::Smo::ApplicationRoleCollection ^ ApplicationRoles { Microsoft::SqlServer::Management::Smo::ApplicationRoleCollection ^ get(); };
[Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcObject(Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcContainerRelationship.ObjectContainer, Microsoft.SqlServer.Management.Sdk.Sfc.Metadata.SfcContainerCardinality.ZeroToAny, typeof(Microsoft.SqlServer.Management.Smo.ApplicationRole))]
public Microsoft.SqlServer.Management.Smo.ApplicationRoleCollection ApplicationRoles { get; }
Public ReadOnly Property ApplicationRoles As ApplicationRoleCollection
Property Value

An ApplicationRoleCollection object that represents all the application roles defined on the database.

Examples

VB

'Connect to the local, default instance of SQL Server.  
Dim srv As Server  
        srv = New Server  

'Reference the AdventureWorks2012 database.  
Dim db As Database  
db = srv.Databases("AdventureWorks2012")  

'Display all the application roles on the database.  
Dim ar As ApplicationRole  
For Each ar In db.ApplicationRoles  
   Console.WriteLine(ar.Name)  
Next  

PowerShell

$srv = new-Object Microsoft.SqlServer.Management.Smo.Server("(local)")  
$db = New-Object Microsoft.SqlServer.Management.Smo.Database  
$db = $srv.Databases.Item("AdventureWorks2012")  
Foreach ($ar in $db.ApplicationRoles)  
{  
   Write-Host $ar.Name  
}  

Remarks

Specific application roles can be referenced by using this collection by specifying the name of the application role. To add a new application role to the collection, call the application role constructor ApplicationRole.

Applies to