Page 1 of 1
Trying to catch error
Posted: Thu 21 Aug 2008 08:03
by oz8hp
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
Posted: Thu 21 Aug 2008 13:17
by Dimon
What's the problem with catching the error? Are you sure that except block was not executed if the connection was established with error?
Try to add the MyDacVcl unit to the uses clause of the unit where Connect is caled, and don't use except block.
Posted: Thu 21 Aug 2008 13:28
by oz8hp
The problem is that I don't get the custom error - just a standard Delphi error and the program crashes.
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

Posted: Fri 22 Aug 2008 12:12
by Dimon
oz8hp wrote:The problem is that I don't get the custom error - just a standard Delphi error and the program crashes.
The program is crashed because you call Halt(9).
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
Try to use the following code:
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_MySQL
Posted: Mon 25 Aug 2008 07:43
by oz8hp
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.)
Posted: Mon 25 Aug 2008 11:28
by eduardosic
oz8hp 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.)
try this
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;
Posted: Mon 25 Aug 2008 13:27
by oz8hp
Makes no difference - still crashing
...raised exception class SocketException with message ''. Proces stopped. Use step..........[/img]
Posted: Mon 25 Aug 2008 13:33
by eduardosic
oz8hp wrote:Makes no difference - still crashing
...raised exception class SocketException with message ''. Proces stopped. Use step..........[/img]
please, send more information, and a complete message.. this exception occurs in other point of you software.
Posted: Tue 26 Aug 2008 05:27
by oz8hp
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?
Posted: Tue 26 Aug 2008 12:20
by eduardosic
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?
Please, send files to
[email protected] or
[email protected]
don't send exe files, gmail block it's.
send-me a screen of error message in you computer.
Posted: Tue 26 Aug 2008 16:33
by eduardosic
eduardosic wrote: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?
Please, send files to
[email protected] or
[email protected]
don't send exe files, gmail block it's.
send-me a screen of error message in you computer.
i receive the files and test it.. work's fine..
i send a e-mail to you with more details