8

My SQL Server's instance name is SQLEXPRESS and SQL Server Service Name looks like MSSQL$SQLEXPRESS. Is there any relation between instance name and service name? I'm trying to check SQL Server Service Status by name and I wonder can SQL Server Service name be different on another computers?

asked Jan 3, 2014 at 9:33

2 Answers 2

14

Yes, the service name is always MSSQL$<Instance Name> for a named instance and MSSQLSERVER for a default instance. I don't believe either can be altered or overridden, nor can I think of any reason why you'd want to.

You can enumerate the installed instances on a server via the registry, using Powershell for example:

Get-ItemProperty 'HKLM:\Software\Microsoft\Microsoft SQL Server\Instance Names\SQL'
answered Jan 3, 2014 at 14:41
1
  • +1 for the answer regarding instance names. That being said, I do prefer not to use the registry directly in powershell unless there isn't another way. For that part, I prefer the approach taken by @ThomasStringer. Using WMI is definitely a more reliable approach. Commented Nov 1, 2016 at 15:37
7

Mark showed you a way to get this information directly from the registry, but another way to do this would be through WMI, consumed by PowerShell:

Get-WmiObject -ComputerName "YourDestinationServer" -Namespace "root\microsoft\sqlserver\computermanagement11" -Class "SqlService" |
 Where-Object {$_.SQLServiceType -eq 1} |
 Select-Object ServiceName, DisplayName, 
 @{Name = "StateDesc"; Expression = {
 switch ($_.State) {
 1 { "Stopped" }
 2 { "Start Pending" }
 3 { "Stop Pending" }
 4 { "Running" }
 5 { "Continue Pending" }
 6 { "Pause Pending" }
 7 { "Paused" }
 }
 }}

The above command will give you the state of the SQL Server engine service(s) on a particular machine.

answered Jan 3, 2014 at 18:58
1
  • I can then assume that the following logic is correct then for named and unnamed instances as service name? svcname = instancename != string.Empty ? string.Format("MSSQL${0}", instancename) : "MSSQLSERVER"; Commented Nov 19, 2018 at 20:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.