ICredentials.Role

Syntax

Role: IApplicationRole;

Description

The Role property determines parameters of the application role.

Comments

The application role is the role on Microsoft SQL DBMS level, which has the rights for certain operations. The application role enables the user to establish the connection to database under the role credentials, after that operations are executed using the established connections. The role usage is available only for DBMS of Microsoft SQL Server type. The user credentials (name, password) specified when establishing the connection do not affect the use of the application role.

The application role is not used by default.

Example

Executing the example requires that the DBMS server has the MyRole role included in the db_owner database. The script for adding the MyRole role to the db_owner database role: execute sp_addrolemember @rolename = 'db_owner', @membername = 'MyRole'. The form contains a button and two EditBox components named EditBox1 and EditBox2.

Sub Button1OnClick;
Var
    MbManager: IMetabaseManager;
    Package: ISecurityPackage;
    PC: IPasswordCredentials;
    Role: IApplicationRole;
    Connection: ISecurityConnection;
    Command: IDalCommand;
    SQL: string;
    Ld: ISecurityPackageLogonData;
Begin
    MbManager := MetabaseManagerFactory.Active;
    Package := MbManager.Packs.FindById("StandardSecurityPackage").Package;
    PC := Package.CreateCredentials(AuthenticationMode.Password) As IPasswordCredentials;
    PC.UserName := EditBox1.Text;
    PC.Password := EditBox2.Text;
    Role := PC.Role;
    Role.Active := True;
    Role.Name := "MyRole";
    Role.Password := "MyRole";
    Role.PasswordSalt := "";
    Role.UseDerivedPassword := False;
    Ld := Package.CreateLogonData("MSSQL2008");
    Ld.ParamValue("SERVER") := "ms2008a";
    Ld.ParamValue("DATABASE") := "P5bash";
    Connection := Package.PerformLogon(True, LD, PC);
    SQL := "create table NewTable(NAME varchar(127) Null, SIZE numeric(24,4) Null)";
    Command := Connection.CreateCommand(SQL);
    Command.Execute;
End Sub Button1OnClick;

Clicking the button creates a table using the credentials of the specified role.

See also:

ICredentials