how to handle exception if MySQL server does not respond ?

Forum related to version 6.5.1 (alpha) and 6.6.x (beta) of ZeosLib's DBOs

Moderators: gto, cipto_kh, EgonHugeist

Post Reply
thcom
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 29.06.2007, 12:51

how to handle exception if MySQL server does not respond ?

Post by thcom »

hi, i try this code:

function ConnectMySQL(iConexe: TZConnection; iIP: String; iDB : String): Boolean;
begin
Screen.Cursor := crSQLWait;
ConnectMySQL := False;
iConexe.HostName := iIP;
iConexe.Database := iDB;
try
iConexe.Connect;
ConnectMySQL := True;
except
on E:Exception do begin
showMessage('Cannot Conect' + Chr(10) + Chr(13) + E.Message);
end;
end; { except }
Screen.Cursor := crDefault;
end;

but if server is down, program crashes without any message
the same problem is when is missing libmysq.dll
any idea, what is wrong ?
thanx thom
User avatar
mdaems
Zeos Project Manager
Zeos Project Manager
Posts: 2766
Joined: 20.09.2005, 15:28
Location: Brussels, Belgium
Contact:

Post by mdaems »

No idea, but can you please post a working (= failing :) ), very simple test project? So I can test/debug it myself. Just zip the source and attach it to this thread. You don't have to include the exe or dll's.

Mark
Image
thcom
Fresh Boarder
Fresh Boarder
Posts: 7
Joined: 29.06.2007, 12:51

Post by thcom »

i am sorry, its little weird, i create litle app with this try connect except block, and everything works fine, but in my big application shows exception only in Delphi IDE in runtime shows UNKNOWN exception :( should i setupo something in delphi menu tools - debug options - OS Exceptions ?
i'm using delphi 7 enterprise with SP1, Win XP x64 Sp2, XAMPP 1.6.7 with MySQL 5.0.51.
You do not have the required permissions to view the files attached to this post.
zippo
Silver Boarder
Silver Boarder
Posts: 322
Joined: 12.10.2005, 18:01
Location: Slovenia

Post by zippo »

I usually use error string parsing. It works perfectly for my needs.

Code: Select all

  except
    on E: Exception do begin
      Result:=false;
      KnownError:=false;
      if Pos('Access denied for user',E.Message)>0 then begin // Unknown user
        KnownError:=true;
        ErrMsg:='Wrong user';
      end;
      if Pos('Can''t connect to',E.Message)>0 then begin
        KnownError:=true;
        ErrMsg:='Unknown server';
      end;
      if Pos('Unknown database',E.Message)>0 then begin
        KnownError:=true;
        ErrMsg:='Unknown database';
      end;
      if not KnownError then
        ErrMsg:=E.Message;
      ShowMessage(ErrMsg);
    end;
  end;
Post Reply