October 17, 2003 at 4:21 am
I want to find whether the given (Server name as input )SQL Server is active or not using T-SQL.
October 18, 2003 at 3:30 am
the two scripts below should give you what you want, the first one uses the SQL dmo object - and the other isql
EXEC master..xp_cmdshell 'isql -L;'
DECLARE @AppObj int
DECLARE @NmList int
DECLARE @Countint
DECLARE @Incrint
DECLARE @server nvarchar(255)
EXEC sp_OACreate 'SQLDMO.Application', @AppObj OUTPUT
EXEC sp_OACreate 'SQLDMO.NameList', @NmList OUTPUT
EXEC sp_OAMethod @AppObj, 'ListAvailableSQLServers', @NmList OUT
EXEC sp_OAGetProperty @NmList, 'Count', @Count OUT
SET @Incr = 1
WHILE @Incr < @Count
BEGIN
SET @server = 'Item('+ CONVERT(varchar,@Incr)+')'
EXEC sp_OAGetProperty @NmList, @server , @server OUT
PRINT @server
SET @Incr = @Incr + 1
END
October 18, 2003 at 3:31 am
sorry - other way round
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply