Best way to check if database server available

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
[email protected]
Posts: 7
Joined: Sat 06 Jan 2018 15:37

Best way to check if database server available

Post by [email protected] » 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?

[email protected]
Posts: 7
Joined: Sat 06 Jan 2018 15:37

Re: Best way to check if database server available

Post by [email protected] » Sat 04 Dec 2021 22:31

Nobody a solution ?

davidmarcus
Posts: 50
Joined: Tue 25 Jan 2005 11:22
Location: Somerville, MA
Contact:

Re: Best way to check if database server available

Post by davidmarcus » Sun 05 Dec 2021 13:48

What is your purpose in doing this?

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Best way to check if database server available

Post by ViktorV » Tue 07 Dec 2021 15:26

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;

Post Reply