views:

308

answers:

2

There are multiple instances of SQL Server 2005 installed on a box. Is there a T-SQL query I can run from Studio that will detect these other instances and their names?

A: 

I highly doubt there's a query you can run to find out instances (you need to be connected to one to run queries) but SQL Server Surface Area Configuration (under Start Menu-->Microsoft SQL Server 2005 --> Configuration Tools) will show you all the instances you have on a given machine.

An alternative might be doing it from code - see this article.

JohnIdol
+2  A: 

I figured out a cheat. It requires using xp_cmdshell and the net start command. I don't know anything about using the net start command and what negative implications that might have. Can anyone advise on that?

create table #test ( srvcs varchar(2000) )
;

insert into #test
exec master..xp_cmdshell 'net start'
;

select 
  substring( srvcs, charindex( '(', srvcs ) + 1, (charindex( ')', srvcs ) - charindex( '(', srvcs ) - 1) ) 
  as srvcs
from #test
where ltrim(srvcs) like '%SQL Server (%'
;

drop table #test
;
Oliver
+1 this is a rather interesting hack - I don't know about the net start cmd but enabling the xp_cmdshell is known to present security issues in particular scenarios. If you're using it in a closed environment though I wouldn't sweat it.
JohnIdol