**
Cannot open MSSQLSSQLEXPRESS service on computer'.'.
**
What I have tried:
Dim myController As New System.ServiceProcess.ServiceController("SQL Server (SQLEXPRESS)")
Private Sub Service_status()
If myController.Status = ServiceProcess.ServiceControllerStatus.Running Then
TextBox1.Text = "Started"
ElseIf myController.Status = ServiceProcess.ServiceControllerStatus.Stopped Then
TextBox1.Text = "Stopped"
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Service_status()
End Sub
Private Sub BtnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStop.Click
ProgressBar1.Value = 0
Try
myController.Stop()
Catch ex As Exception
MsgBox(ex.Message)
Finally
ProgressBar1.Value = 100
myController.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped) '//Add
Service_status()
End Try
End Sub
Private Sub BtnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnStart.Click
ProgressBar1.Value = 0
Try
myController.Start()
Catch ex As Exception
MsgBox(ex.Message)
Finally
ProgressBar1.Value = 100
myController.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running) '//Add
Service_status()
End Try
End Sub