Page 1 of 1

Best way to check if database server available

Posted: Tue 09 Nov 2021 17:12
Hi,

What's the best way to check if a database server/database is available BEFORE making a connection?

Re: Best way to check if database server available

Posted: Sat 04 Dec 2021 22:31
Nobody a solution ?

Re: Best way to check if database server available

Posted: Sun 05 Dec 2021 13:48
by davidmarcus
What is your purpose in doing this?

Re: Best way to check if database server available

Posted: Tue 07 Dec 2021 15:26
by ViktorV
Unfortunally, MySQL does not support the ability to know if a server is available without trying to connect to it, so MyDAC does not support this functionality either.

Kindly note that you can use the following code to solve your issue:

Code: Select all

try
  MyConnection1.Connect;
except
  on E: EMyError do
    if EMyError(E).ErrorCode = 2003 then
      ShowMessage('Can''t connect to MySQL server -' + MyConnection1.Server + #13#10);
    else
      raise;
end;