exception handeling connecting tot mysql server/database

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
alpha
Posts: 9
Joined: Thu 15 Jan 2009 22:57

exception handeling connecting tot mysql server/database

Post by alpha » Mon 22 Feb 2010 21:44

Hi All,

probably a trivial question, but how do I handel errors occuring when for example my sql server is down, or there is some other problem conecting to the database?
try .. except

Thnks
Simon

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

Post by Dimon » Tue 23 Feb 2010 10:50

You can process an exception on connecting like this:

Code: Select all

  try
    MyConnection.Connect;
  except
    on e: EDAError do
      if e.Message = '' then
      // processing of message
  end;

alpha
Posts: 9
Joined: Thu 15 Jan 2009 22:57

Post by alpha » Tue 23 Feb 2010 11:15

Tnks for the reply.
Unfortunately your solution does not work.
I still get the eroor message:
".. raised exception class SocketException..." when de mysql server is not available

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

Post by Dimon » Tue 23 Feb 2010 14:19

Then you can use the SocketException class, or the Exception class, like this:

Code: Select all

  try 
    MyConnection.Connect; 
  except 
    on e: EDAError do 
      // processing of message 
    on e: SocketException do 
      // processing of message 
    on e: Exception do 
      // processing of message 
  end;

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

Post by Dimon » Tue 23 Feb 2010 14:19

Please, specify what error does arise?

alpha
Posts: 9
Joined: Thu 15 Jan 2009 22:57

Post by alpha » Tue 23 Feb 2010 19:55

When de server is not available, and thus the mysql database not reachable the statement myconnection.connect generates the error:
.. raised exception class SocketException...
The advice given above generates a compilation error in the statement:
on e: SocketException do
because SocketException is not known.
Probably I must ad a unit to the uses clause? Which? I could not find it in the help

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

Post by Dimon » Wed 24 Feb 2010 10:01

If you use the SecureBridge components, you should inlude the ScSSHUtil unit to the uses clause, if not - add the CRVioTcp unit.

Post Reply