Dave Huang
Dave Huang

Reputation: 746

How to get a list of all the MS SQL Server instances on the local machine?

This seems to be a fairly common question, but none of the answers I've seen have been particularly satisfactory. I want to get a list of the names of the MS SQL Server instances installed on the local machine, regardless of whether they're started or not. For the purposes of this discussion, I'm OK with just finding instances of SQL 2005 and newer; I can handle 2000 and earlier using "legacy" methods (i.e., look in the registry). What I do require is that it not be dependent on the SQL Server Browser service (it's disabled by default nowadays), and that 64-bit instances are returned even when the app is 32-bit.

Suggestions I've seen:

So, are there some other methods that might work better?

Upvotes: 31

Views: 69463

Answers (6)

Dmitry Bykov
Dmitry Bykov

Reputation: 11

It's may be, that SQL Server fully local and it have not remote access. By example, SQL Server Express is local. So, sqlcmd -L cannot find the local server because this server is not responding to the broadband access request.

I use this command

sc queryex | grep "MSSQL" It return, for example

Service_Name: MSSQL$SQLEXPRESS2 Service_Name: MSSQL$SQLEXPRESS It get list of all system services and find services with name constraints "MSSQL". It return list of system services for every MS SQL instances. But it return only local instances, on current machine, for remote server, on remote machine, use sqlcmd -L.

Upvotes: 0

eckes
eckes

Reputation: 10433

The SQL Browser service (if active) speaks SSRP/MS-SQLR on UDP Port 1434.

It is the component which is used for remote discovery of instances (and also determining their port). It helps also discovery in a network.

It is however disabled by default (good thing for surface reduction).

Upvotes: 3

Chas Long
Chas Long

Reputation: 61

From a command prompt (cmd.exe):

sc query|findstr "DISPLAY_NAME"|findstr /C:"SQL Server (" > myfile.txt

FOR /F " tokens=2 delims=()" %i in (myfile.txt) do @echo %computername%\%i

Upvotes: 6

Bill Greer
Bill Greer

Reputation: 3166

I know this is an older post, but I did come to this post today looking for a way to find installed instances of SQL Server. Although the two answers given are helpful, I think they only pertain to installed and running instances of SQL Server. If SQL Server Configuration Manager is installed, all installed instances should be listed under the SQL Server Services node. Here you might find an instance that is installed, but not running. You can right click the instance and start it. I am sure there are other ways to do this; it is just a way that came in handy for me today and I thought I would share it.

Upvotes: 3

Jeswin
Jeswin

Reputation: 116

This might be helpful , i have tried this in Sql Server 2008 :

select * from sys.servers

Upvotes: 2

8kb
8kb

Reputation: 11406

I am able to see both 2005 and 2008 SQL Server instances on my laptop using Powershell:

Get-Service | Where-Object {$_.Name -like 'MSSQL$*'}

Other possibilities to explore include enumerating through the RegisteredServers namespace.

Upvotes: 14

Related Questions