Author: Nik Ozniev
Can I find programmatically if certain MS SQL Server is reachable on net?
Answer:
Here is function, performing check if MS SQL Server is reachable on net against
given server name (usually host on that MS SQL Server is installed), user name and
password
1 2 function CheckMSSQLServer(fServerName, fUserName, fPsw: string): Bool;
3 var4 wDb: TDatabase;
5 begin// Check if MS SQL Server is reachable6 // Important! BDE Must be installed7 Result := False;
8 wDb := TDatabase.Create(nil);
9 10 with wDb do11 begin12 DatabaseName := 'wDbDatabaseName'; // arbitrary name, must be unique13 // in current Session14 Params.Values['SERVER Name'] := fServerName;
15 Params.Values['USER Name'] := fUserName;
16 Params.Values['PASSWORD'] := fPsw;
17 LoginPrompt := False;
18 end;
19 20 try21 wDb.DriverName := 'MSSQL';
22 try23 wDb.Connected := True;
24 wDb.Connected := False;
25 except26 ShowMessage('Server is not reachable');
27 end;
28 Result := True;
29 finally30 wDb.Free;
31 end;
32 end;