Trying to catch error
Trying to catch error
I am using the code below to try and test the connection to my MySQL server, but it doesn't do the job. It doesn't catch the error with the wrong settings of servername, user and password.
I am rather new both to Delphi and MyDAC so please bear with my code
Procedure TfrmMain.hp_Validate_MySQL();
Var
strMessage : String;
Begin
strMessage := 'There was a problem in connection to MySQL server: ' + strMySQL_Server + ' !' + hp_NewLine;
strMessage := strMessage + 'Revise your settings in the .INI file';
Try
conMySQL_1.Server := 'kurt';
conMySQL_1.Database := 'Test';
conMySQL_1.Username := 'root';
conMySQL_1.Password := '';
conMySQL_1.Connect;
Except
On E: EMyError Do
If E.Errorcode = ER_ACCESS_DENIED_ERROR Then
Begin
MessageDlg(strMessage, mtError, [mbOK], 0);
Halt(9);
End
Else
Begin
ShowMessage(IntToStr(E.Errorcode));
Raise;
End;
End; //Try
End; //hp_Validate_MySQL
I am rather new both to Delphi and MyDAC so please bear with my code
Procedure TfrmMain.hp_Validate_MySQL();
Var
strMessage : String;
Begin
strMessage := 'There was a problem in connection to MySQL server: ' + strMySQL_Server + ' !' + hp_NewLine;
strMessage := strMessage + 'Revise your settings in the .INI file';
Try
conMySQL_1.Server := 'kurt';
conMySQL_1.Database := 'Test';
conMySQL_1.Username := 'root';
conMySQL_1.Password := '';
conMySQL_1.Connect;
Except
On E: EMyError Do
If E.Errorcode = ER_ACCESS_DENIED_ERROR Then
Begin
MessageDlg(strMessage, mtError, [mbOK], 0);
Halt(9);
End
Else
Begin
ShowMessage(IntToStr(E.Errorcode));
Raise;
End;
End; //Try
End; //hp_Validate_MySQL
The program is crashed because you call Halt(9).oz8hp wrote:The problem is that I don't get the custom error - just a standard Delphi error and the program crashes.
Try to use the following code:oz8hp wrote:I will try to see if I can test your suggestion, but I am not quite sure how to do it. But I will have to try
Code: Select all
uses
MyDacVcl;
Procedure TfrmMain.hp_Validate_MySQL();
Begin
conMySQL_1.LoginPrompt := True;
conMySQL_1.Server := 'kurt';
conMySQL_1.Database := 'Test';
conMySQL_1.Username := 'root';
conMySQL_1.Password := '';
conMySQL_1.Connect;
End; //hp_Validate_MySQLThe only difference is that I then get a logon prompt for the MySQL server.
Since the app has to be 100% unattended I can't use that option.
(The app is a converter that takes >500 Paradox tables of different kind and convert to MySQL tables - is is being run by a server in the middle of the night and if errors occur the app sends a mail to SYSOP calling for his attention.)
Since the app has to be 100% unattended I can't use that option.
(The app is a converter that takes >500 Paradox tables of different kind and convert to MySQL tables - is is being run by a server in the middle of the night and if errors occur the app sends a mail to SYSOP calling for his attention.)
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
try thisoz8hp wrote:The only difference is that I then get a logon prompt for the MySQL server.
Since the app has to be 100% unattended I can't use that option.
(The app is a converter that takes >500 Paradox tables of different kind and convert to MySQL tables - is is being run by a server in the middle of the night and if errors occur the app sends a mail to SYSOP calling for his attention.)
Code: Select all
Procedure TfrmMain.hp_Validate_MySQL();
Begin
try
conMySQL_1.Server := 'kurt';
conMySQL_1.Database := 'Test';
conMySQL_1.Username := 'root';
conMySQL_1.Password := '';
conMySQL_1.Connect;
except
on E:Exception do begin
MessageDlg( 'There was a problem in connection to MySQL server: ' + #13 + E.Message, mtError, [mbOK], 0);
end
end;
end;
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
Please, send files to [email protected] or [email protected]oz8hp wrote:What I could do is to send you a copy of my test app. It is just a form with a connection and a button that runs the function to validate the connection no more.
Is there anywhere I can send the file?
don't send exe files, gmail block it's.
send-me a screen of error message in you computer.
-
eduardosic
- Posts: 387
- Joined: Fri 18 Nov 2005 00:26
- Location: Brazil
i receive the files and test it.. work's fine..eduardosic wrote:Please, send files to [email protected] or [email protected]oz8hp wrote:What I could do is to send you a copy of my test app. It is just a form with a connection and a button that runs the function to validate the connection no more.
Is there anywhere I can send the file?
don't send exe files, gmail block it's.
send-me a screen of error message in you computer.
i send a e-mail to you with more details