DEV Community

Dejan Dozet
Dejan Dozet

Posted on

TADOConnection: Proper Use of LoginPrompt

When using TADOConnection in Delphi, you may want to control when the login dialog appears. Setting LoginPrompt to True triggers the prompt each time a connection is attempted, which is useful if credentials aren’t stored in the connection string.

Example Usage

Here's an example illustrating conditional use of LoginPrompt:

procedure TfrmMain.FormShow(Sender: TObject);
var
  i: integer;
begin
  con1.Provider := 'SQLOLEDB.1';
  con1.Properties['Application Name'].Value := Application.Title;
  with TIniFile.Create(ExtractFileDir(ParamStr(0)) + '\setup.ini') do
  begin
    con1.Properties['Initial Catalog'].Value := ReadString('database', 'Initial Catalog', '');
    con1.Properties['Data Source'].Value := ReadString('database', 'Data Source', '');
    if ReadBool('database', 'Integrated Security', false ) then
    begin
      con1.Properties['Integrated Security'].Value := 'SSPI';
      con1.Properties['Persist Security Info'].Value := 'False';
      con1.LoginPrompt := False;
    end
    else
    begin
      con1.Properties['Persist Security Info'].Value := 'True';
      con1.LoginPrompt := true;
    end;
  end;
end;

procedure TfrmMain.con1Login(Sender: TObject; Username, Password: string);
begin
  con1.Properties['User ID'].Value := Username;
  con1.Properties['Password'].Value := Password;
end;
Enter fullscreen mode Exit fullscreen mode

In this case, the prompt appears only when credentials are missing, providing flexibility and enhancing security.

Tips

  1. Conditionally prompt: Use LoginPrompt based on your security needs.
  2. Avoid hardcoded credentials: Protect sensitive data when LoginPrompt is enabled.
  3. Consistent user experience: Keep the prompt behavior uniform across your app.

Final Thoughts

Using LoginPrompt wisely can simplify the user experience while ensuring secure access.

For more details about it and much more similar posts, check this page on my blog: TADOConnection: Correct Way to Use LoginPrompt.

Image of Timescale

🚀 pgai Vectorizer: SQLAlchemy and LiteLLM Make Vector Search Simple

We built pgai Vectorizer to simplify embedding management for AI applications—without needing a separate database or complex infrastructure. Since launch, developers have created over 3,000 vectorizers on Timescale Cloud, with many more self-hosted.

Read more →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay