API:FireDAC.Comp.Client.TFDConnection.OnLogin

From RAD Studio API Documentation
Jump to: navigation, search

Delphi

property OnLogin: TFDConnectionLoginEvent read FOnLogin write FOnLogin;

C++

__property OnLogin;

Properties

Type Visibility Source Unit Parent
event published
FireDAC.Comp.Client.pas
FireDAC.Comp.Client.hpp
FireDAC.Comp.Client TFDConnection

Description

Fires when an application connects to a DBMS.

FireDAC.Comp.Client.TFDConnection.OnLogin inherits from FireDAC.Comp.Client.TFDCustomConnection.OnLogin. All content below this line refers to FireDAC.Comp.Client.TFDCustomConnection.OnLogin.

Fires when an application connects to a DBMS.

Write an OnLogin event handler to take specific actions when an application attempts to connect to a DBMS.

When the LoginPrompt property is True, a database login is required. The OnLogin event or a login dialog only occurs when the LoginPrompt property is True. The login dialog is shown only if OnLogin event handler is not assigned.

If there is no OnLogin event handler, the current User_Name, Password, and other parameters are read from the Params property or connection definition, and a standard login dialog box opens. The dialog prompts for a user name, password, and other optional parameters, and then uses the values entered by the user to set the User_Name, Password and other optional values in the Params property. These values are then passed to the DBMS.

The event handler for OnLogin receives the following parameters:

Applications that provide an OnLogin event handler can fill or modify the connection parameters, such as AParams.UserName or AParams.Password. AParams is a temporary object, and is freed automatically when no longer needed.

A password provided using an OnLogin event handler or a standard login dialog is erased from memory after login. A password provided in BeforeConnect is not erased.

Example

procedure TForm1.FDConnection1Login(AConnection: TFDCustomConnection; AParams: TFDConnectionDefParams);
begin
  AParams.UserName := 'dba';
  AParams.Password := InputBox('Login', 'Please enter DBA password', 'sql');
end;

procedure TForm1.Button1Click(ASender: TObject);
begin
  FDConnection1.OnLogin := FDConnection1Login;
  FDConnection1.LoginPrompt := True;
  FDConnection1.Connected := True;
end;

See Also