Trying to catch error

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Trying to catch error

Post by oz8hp » Thu 21 Aug 2008 08:03

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

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Thu 21 Aug 2008 13:17

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.

oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Post by oz8hp » Thu 21 Aug 2008 13:28

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 :lol:

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 22 Aug 2008 12:12

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

oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Post by oz8hp » Mon 25 Aug 2008 07:43

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.)

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Post by eduardosic » Mon 25 Aug 2008 11:28

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; 


oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Post by oz8hp » Mon 25 Aug 2008 13:27

Makes no difference - still crashing

...raised exception class SocketException with message ''. Proces stopped. Use step..........[/img]

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Post by eduardosic » Mon 25 Aug 2008 13:33

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.

oz8hp
Posts: 151
Joined: Mon 18 Feb 2008 13:28
Location: Denmark
Contact:

Post by oz8hp » Tue 26 Aug 2008 05:27

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?

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Post by eduardosic » Tue 26 Aug 2008 12:20

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.

eduardosic
Posts: 387
Joined: Fri 18 Nov 2005 00:26
Location: Brazil

Post by eduardosic » Tue 26 Aug 2008 16:33

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

Post Reply