How to find ACTIVE Sql Servers in LAN

  • I want to find whether the given (Server name as input )SQL Server is active or not using T-SQL.

  • 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

  • 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