i use a secure .ini file which contains the settings for connecting to
a database (user, password, database, port and server name (IP nr).
Within the OnCreate event from a datamodule i use this settings to make the connection. When some of the settings are wrong (wrong password)
the user gets the default (i think MYSQL) message "'Access denied
for user ....''.
Is it possible to disable this message and use something like :
if not MyConnection.Connected then ....
message.....
else
......
I did try this but can't get is working....within the datamodule OnCreate event i use the following code to connect :
Code: Select all
procedure TdmTables.DataModuleCreate(Sender: TObject);
var
IniFile : TIniFile;
i : integer;
begin
cMapProg:= ExtractFilePath(Application.ExeName);
if not fileExists(cMapProg+'database.dat') then begin
Application.MessageBox('Settings file does not exist !'+#10+''+#10+'The applications will be terminated', 'Warning !', MB_OK+MB_ICONHAND+MB_DEFBUTTON1+MB_APPLMODAL);
Application.Terminate;
end;
if fileExists(cMapProg+'database.dat') then begin
// Call .ini file to read settings
GetSetting;
// variabelen toekennen
dmTables.MyConnection.Server:=cRemoteserver;
dmTables.MyConnection.Database:=cRemoteDB;
dmTables.MyConnection.Username:=cRemoteUser;
dmTables.MyConnection.Password:=cRemotePassword;
dmTables.MyConnection.Port:=strTOint(cRemotePort);
dmTables.MyConnection.Connected:=true;
if not dmTables.MyConnection.Connected then begin
MessageDlg('Warning' + #10 + '' + #10 + 'It's not possible to maken connection with database.' + #10 + 'Application will be terminated !', mtError, [mbOK], 0);
Application.Terminate;
end;
if dmTables.MyConnection.Connected then begin
for i := 0 to dmTables.ComponentCount -1 do begin
if Components[i] is TMyQuery then begin
(Components[i] as TMyQuery).Active := true;
end;
end;
end;
end;
end;