Page 1 of 1
checkk if SQL Sever is ready for client connection
Posted: Fri 07 Dec 2012 09:41
by formi
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
Re: checkk if SQL Sever is ready for client connection
Posted: Fri 07 Dec 2012 10:10
by AndreyZ
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;
Re: checkk if SQL Sever is ready for client connection
Posted: Fri 07 Dec 2012 10:47
by formi
Thanks!
Re: checkk if SQL Sever is ready for client connection
Posted: Fri 07 Dec 2012 11:15
by AndreyZ
Feel free to contact us if you have any further questions about UniDAC.