Board index » delphi » MS SQL server is running?

MS SQL server is running?


2003-12-28 12:18:37 AM
delphi281
How to detect that MS SQL Server is running? One idea is to detect port
1499, but that is just like hard coded "C:\Windows" ...
Any more ides,
Adnan
 
 

Re:MS SQL server is running?

const
SQLDMOSQLVer_80 = $00000010; // 2000
function MS SQLPingSQLServerVersion(const fServerName, fUserName, fPassword: string):
single;
var
fSQLServer: _SQLServer;
fSQLDMO_SQL_VER: TOleEnum;
begin
fSQLServer := CoSQLServer.create;
fSQLDMO_SQL_VER := fSQLServer.PingSQLServerVersion(fServerName,fUserName,fPassword);
fSQLServer := nil;
case fSQLDMO_SQL_VER of
SQLDMOSQLVer_Pre_60: result := 5.0;
SQLDMOSQLVer_60 : result := 6.0;
SQLDMOSQLVer_65 : result := 6.5;
SQLDMOSQLVer_70 : result := 7.0;
SQLDMOSQLVer_80 : result := 8.0;
else result := 0.0;
end;
end;
This requires that the sqldmo runtime be installed on the client.
Dennis Passmore
Ultimate Software, Inc.
 

Re:MS SQL server is running?

1499 is not one of the default SQL Server ports and there is no certaintly
that it will be using the default (1433) port anyway.
Dennis's use of DMO is a good way to detect using DMO, there are a couple of
other options:
1/ Use the Win32 Service APIs through WMI or Win32. SQL 7 and earlier the
services is called MS SQLServer, this is true for default instances of SQL
Server in SQL2000 as well. Named instances of SQL Server 2000 follow the
form MS SQLServer$<InstanceName>for the service naming.
Using this info, as long as you know the version and the name of the
instance you can check if its running.
2/ You can also just try and connect and trap the failure message. If the
account your app is running under is an NT Account with rights to SQL Server
then just do a connect using ADO or whatever, if it works, the service is
running, if it fails with a message something like this "The SQL Server does
not exist or is not running" then chances are its not running.
-Euan
"Adnan Hebibovic" <XXXX@XXXXX.COM>writes
Quote
How to detect that MS SQL Server is running? One idea is to detect port
1499, but that is just like hard coded "C:\Windows" ...

Any more ides,

Adnan


 

Re:MS SQL server is running?

Thanks
"Euan Garden" <XXXX@XXXXX.COM>writes
Quote
1499 is not one of the default SQL Server ports and there is no certaintly
that it will be using the default (1433) port anyway.

Dennis's use of DMO is a good way to detect using DMO, there are a couple
of
other options:

1/ Use the Win32 Service APIs through WMI or Win32. SQL 7 and earlier the
services is called MS SQLServer, this is true for default instances of SQL
Server in SQL2000 as well. Named instances of SQL Server 2000 follow the
form MS SQLServer$<InstanceName>for the service naming.

Using this info, as long as you know the version and the name of the
instance you can check if its running.

2/ You can also just try and connect and trap the failure message. If the
account your app is running under is an NT Account with rights to SQL
Server
then just do a connect using ADO or whatever, if it works, the service is
running, if it fails with a message something like this "The SQL Server
does
not exist or is not running" then chances are its not running.

-Euan

"Adnan Hebibovic" <XXXX@XXXXX.COM>writes
news:XXXX@XXXXX.COM...
>How to detect that MS SQL Server is running? One idea is to detect port
>1499, but that is just like hard coded "C:\Windows" ...
>
>Any more ides,
>
>Adnan
>
>