SQL-DMO获得本地服务器列表

谈不上什么技术含量,只是调用了几个方法和属性。有人问到了就写了下

http://topic.csdn.net/u/20090822/09/fd0983b9-a656-4cff-ab78-c4bd8ce033bf.html?34690

/* fcuandy 08/23/2009 */ DECLARE @obj INT, @list INT, @i INT, @cnt INT, @name VARCHAR(100), @err INT DECLARE @t TABLE(ServerName VARCHAR(100)) EXEC @err = sp_OACreate 'SQLDMO.Application',@obj OUTPUT EXEC @err = sp_OAGetProperty @obj,'ListAvailableSQLServers',@list OUTPUT EXEC @err = sp_OAGetProperty @list,'Count',@cnt OUTPUT SELECT @cnt,@err,@list SET @i=1 WHILE @i<=@cnt BEGIN EXEC @err = sp_OAGetProperty @list,'Item',@name OUTPUT,@i INSERT @t SELECT @name SET @i=@i+1 END EXEC @err = sp_OADestroy @list EXEC @err = sp_OADestroy @obj SELECT ServerName FROM @t /* ServerName ROBINWEN/SQL2005 */ 

 

你可能感兴趣的:(SQL-DMO获得本地服务器列表)