Role: IApplicationRole;
The Role property determines parameters of the application role.
The application role is meant as the role on MS SQL DBMS level, which has the rights for certain operations. The application role use enables the user to establish the connection to database under the role credentials, after that operations are performed 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 usage of the application role.
The application role is not used by default.
Executing the example requires the MyRole role that must be contained in the 'db_owner' database, that needs to be created on the DBMS server. The script for adding "MyRole" to the 'db_owner' database role: execute sp_addrolemember @rolename = 'db_owner', @membername = 'MyRole'. The form must contain the EditBox1 and EditBox2 of the EditBox type.
Sub UserProc;
Var
MbManager: IMetabaseManager;
Package: ISecurityPackage;
PC: IPasswordCredentials;
Role: IApplicationRole;
C : 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";
C := Package.PerformLogonRoleO(0, Ld, PC, 0, 0);
sql := "create table NewTable(NAME varchar(127) Null, SIZE numeric(24,4) Null)";
Command := C.CreateCommand(sql);
Command.Execute;
End Sub Button2OnClick;
After executing the example the table is created under the role credentials.
See also: