views:

21

answers:

1

My application connects to an arbitrary (configurable) instance of SQL Server.

If the instance is local, the application needs to ensure that the SQL service is started before connecting.

Given the name of the instance, how do I determine the name of the service to start?

+1  A: 

Per Books Online, the default instance service name called MSSQLSERVER and named instances have the service name MSSQL$InstanceName. See "Setting Up Windows Service Accounts" in Books Online.

I suppose there's a theoretical corner case where someone has managed to install MSSQL with different service names, but that seems extremely unlikely. And if someone does, they should expect to have problems.

Depending on your target application userbase, you might just try to connect to the instance and if it fails ask the user to ensure it's running and the name is correct. Or you could enumerate all instances on the box and ask them to pick one (there are a few questions here about enumerating instances).

Pondlife