W
W
White_Bambie2018-12-26 10:01:29
Delphi
White_Bambie, 2018-12-26 10:01:29

Why can't ADO connect to MS Access DB?

In the form, I prescribe a procedure for adding a connection to the access databases, but the latter is not connected. I am using Delphi XE7
development environment .

procedure TfMain.FormCreate(Sender: TObject);
begin
  GetDir(0, DIR);
try
  fDM.ADOConnection1.LoginPrompt := False;
  fDM.ADOConnection1.Connected := False;
    fDM.ADOConnection1.ConnectionString :='Provider=Microsoft.Jet.OLEDB.4.0;' + 'Data Source=' + DIR +'/DB/DB.mdb;' + 'Persist Security Info=False;';
  fDM.ADOConnection1.Connected := True;
except
  MessageBox(Handle,'Произошла ошибка при подключении к базе данных!','Ошибка!',MB_ICONERROR + MB_OK);
  Application.Terminate;
  end;
end;

I can't figure out what's wrong... Help with good advice :)
ps: in Data Module Create, the procedure works and the database is connected. And why through the main form is not present?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Konstantin Tsvetkov, 2018-12-26
@White_Bambie

Data Module Create procedure works and the basis is connected. And why through the main form is not present?
If fDMnot already created, then it cannot be used.

K
Kot-da-Vinci, 2019-01-05
@Kot-da-Vinci

Usually, in order to understand what the error is, they look at least the text of the message of the exception that has arisen, and even its class. And don't do "Oh!" and "Application.Terminate".
Something like this, for example:

except
  on E: Exception do
  begin
    MessageBox(Handle,
      'Произошла ошибка при подключении к базе данных!' + sLineBreak 
        + E.ClassName + ': ' + E.Message, 
      'Ошибка!',
      MB_ICONERROR + MB_OK);
    Application.Terminate;
  end;
end;

The answer to your question has already been written to you.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question