TADOConnection – Correct way to use LoginPrompt

I never really understand LoginPrompt := true property in TADOConnection Delphi class untill today.

Correct way to use it is like this:

procedure TfrmMain.FormShow(Sender: TObject);
  i: integer;
  con1.Provider := 'SQLOLEDB.1';
  con1.Properties['Application Name'].Value := Application.Title;
  with TIniFile.Create(ExtractFileDir(ParamStr(0)) + '\setup.ini') do
    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
      con1.Properties['Integrated Security'].Value := 'SSPI';
      con1.Properties['Persist Security Info'].Value := 'False';
      con1.LoginPrompt := False;
      con1.Properties['Persist Security Info'].Value := 'True';
      con1.LoginPrompt := true;

procedure TfrmMain.con1Login(Sender: TObject; Username, Password: string);
  con1.Properties['User ID'].Value := Username;
  con1.Properties['Password'].Value := Password;


This code reads some properties needed by connection string from an INI file. Then based on the value of Integrated Security property that it finds in the file it decides if it should use integrated security (Windows) or SQL Server security to connect to the db. If it uses SQL Server security then OnLogon event will be called upon calling Open method on connection. But before that user will be prompted to enter username and password for DB. You can set these properties then in that event.

It is important to use Properties collection and set the value to property that is needed to be initialized not the connection string itself! Because simply StringReplace will not work!

If you're looking for top-tier software developer to hire, look no further!

What I offer:

  • Website Development: Turn your idea into a fully functional website.
  • Mobile App Creation: Reach your audience on every device.
  • Custom Software Solutions: Software tailored to your business needs.
  • Database Management: Ensure your data is structured, secure, and accessible.
  • Consultations: Not sure where to start? Let's discuss the best tech solutions for your goals.

With 20+ years of experience in the tech industry, I've honed my skills to provide only the best for my clients. Let's turn your vision into reality. Contact me today to kick off your next digital project!