* * *

Author Topic: MySQL different exception for hosntame and username ?  (Read 256 times)

mirce.vladimirov

  • Full Member
  • ***
  • Posts: 208
MySQL different exception for hosntame and username ?
« on: April 20, 2017, 04:37:51 pm »
I'm using this code to login to a MySQL server :
Code: Pascal  [Select]
  1.   try
  2.     MySQL50Connection1.Connected:=true;
  3.   except
  4.       on E : Exception do
  5.          if E is EDatabaseError  then
  6.             showmessage('Unknown hostname or username:' + E.Message)
  7.           else
  8.             showmessage('Error: ' + E.ClassName + sLineBreak +  '  message is: ' + E.Message);
  9.  
  10.  end;
  11.  

This way I cant tell what was wrong, the hostname or the username, the error message is always the same: "Server connect failed".
Is there a possibility to get the exact reason of the failure: hostname unknow, username unknown ?

Thanks

Leledumbo

  • Hero Member
  • *****
  • Posts: 7529
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: MySQL different exception for hosntame and username ?
« Reply #1 on: April 20, 2017, 09:17:01 pm »
Instead of EDatabaseError, try handling ESQLDatabaseError. That one has ErrorCode field (DBMS specific) which can describe what error you get. Consult MySQL documentation for the list.

mirce.vladimirov

  • Full Member
  • ***
  • Posts: 208
Re: MySQL different exception for hosntame and username ?
« Reply #2 on: April 20, 2017, 10:16:04 pm »
This is what I get
Quote
najava.pas(119,14) Error: Identifier not found "ESQLDatabaseError"

when I try to compile this
Code: Pascal  [Select]
  1.   try
  2.     MySQL50Connection1.Connected:=true;
  3.   except
  4.     // will only be executed in case of an exception
  5.       on E : EDatabaseError do
  6.              showmessage('Unknown server or username :' + E.ClassName + sLineBreak +  ' message is: ' + E.Message) ;
  7.       on e : ESQLDatabaseError do
  8.             showmessage('nn:' + E.ClassName + sLineBreak +  ' message is: ' + E.Message) ;
  9.       on E : Exception do
  10.             showmessage('Error: ' + E.ClassName + sLineBreak + 'a:' + LineEnding + ' message is: ' + E.Message);
  11.          edit_ime.SetFocus;
  12.          exit;
  13.       end;                                        


 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus