Recent

Author Topic: how i can test the connection with mysql?  (Read 2558 times)

saul_linux

  • Newbie
  • Posts: 1
how i can test the connection with mysql?
« on: September 03, 2014, 06:54:55 am »
I am do a litle app, i need check if the server of mysql is down, but i don't know.
I am using the MySQL55Connection  componet
i tried
Code: [Select]
   try
     MySQL55Connection1.Open;

   finally
     if MySQL55Connection1.Connected=false then
     begin
        ShowMessage('connection fail');

     end;
   end; 
   


but when mysql is down, my app doesn't anything
 
« Last Edit: September 03, 2014, 06:56:54 am by saul_linux »

dogriz

  • Full Member
  • ***
  • Posts: 127
Re: how i can test the connection with mysql?
« Reply #1 on: September 03, 2014, 07:43:55 am »
Try like this:
Code: [Select]
   try
     MySQL55Connection1.Open;
     if MySQL55Connection1.Connected=false then
        ShowMessage('connection fail');
   except
      //code for exception if you need it
   end; 
FPC 3.2.2
Lazarus 2.2.4
Debian x86_64, arm

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: how i can test the connection with mysql?
« Reply #2 on: September 03, 2014, 07:48:37 am »
in order to test if the sql server is present the only thing you need to have a simple tcp connection with the server succeed mysqlConnection does a lot more than opening a connection to the server it also initializes the server and client connection parameters and transactions.
forget about testing with the MySQLConnection use a simple tcp client to connect to the server's ip and port make sure that the time out interval is small enough to avoid user waiting and big enough to allow the connection to take place before the time out. 
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018