In my application events class startup, I check to see if the SQLSERVER service is running, if not then I would like to start the service. I have found some code that checks that status and then starts the service, but I keep getting an error message 'Cannot open MSSQLSERVER service on computer '.'. I've verified the Service Name in the properties window and even tried the display name with no luck. Googling keeps going back to check status and then start service. Here is the code:
Dim service As New ServiceController("MSSQLSERVER")
If service.Status = ServiceControllerStatus.Stopped Or service.Status = ServiceControllerStatus.Paused Then
Try
service.Start()
Catch ex As Exception
MsgBox("StartService error: " & ex.Message)
End Try
End If
Could I missing a reference?
Any help is much appreciated, thanks.
William