From RAD Studio API Documentation
Jump to: navigation, search


property OnLogin: TFDConnectionLoginEvent read FOnLogin write FOnLogin;


__property TFDConnectionLoginEvent OnLogin = {read=FOnLogin, write=FOnLogin};


Type Visibility Source Unit Parent
event public
FireDAC.Comp.Client TFDCustomConnection


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.


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

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

See Also