Answer the question
In order to leave comments, you need to log in
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;
Answer the question
In order to leave comments, you need to log in
Data Module Create procedure works and the basis is connected. And why through the main form is not present?If
fDM
not already created, then it cannot be used.
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;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question