checkk if SQL Sever is ready for client connection

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
formi
Posts: 39
Joined: Thu 17 Apr 2008 13:01

checkk if SQL Sever is ready for client connection

Post by formi » Fri 07 Dec 2012 09:41

Hi

what is the best way to check if the SQLserver is ready to establish a connection from a client?

Thanks for your answer

Peter

AndreyZ

Re: checkk if SQL Sever is ready for client connection

Post by AndreyZ » Fri 07 Dec 2012 10:10

Hello,

The only way to check if SQL Server is available and allows connecting to it, is to make a connection attempt. Here is a code example:

Code: Select all

var
  con: TUniConnection;
begin
  con := TUniConnection.Create(nil);
  try
    try
      con.ProviderName := 'SQL Server';
      con.Server := 'server';
      con.Database := 'database';
      con.Username := 'username';
      con.Password := 'password';
      con.LoginPrompt := False;
      con.Open;
      ShowMessage('SQL Server is available');
    except
      on E: Exception do
        ShowMessage(E.Message);
    end;
  finally
    con.Free;
  end;
end;

formi
Posts: 39
Joined: Thu 17 Apr 2008 13:01

Re: checkk if SQL Sever is ready for client connection

Post by formi » Fri 07 Dec 2012 10:47

Thanks!

AndreyZ

Re: checkk if SQL Sever is ready for client connection

Post by AndreyZ » Fri 07 Dec 2012 11:15

Feel free to contact us if you have any further questions about UniDAC.

Post Reply