如何启用实时服务控制器报告?

How to enable Live Service Controller Reporting?

申请截图:

申请代码:

Dim myController As New System.ServiceProcess.ServiceController("SQL Server (SQLEXPRESS)")
Sub ed()
    If txtNum.Text = "Started" Then
        btnStart.Enabled = False
        btnStop.Enabled = True
    ElseIf txtNum.Text = "Stopped" Then
        btnStop.Enabled = False
        btnStart.Enabled = True
    End If
End Sub
Sub Na1()
    If myController.Status = ServiceProcess.ServiceControllerStatus.Running Then
        txtNum.Text = "Started"
    ElseIf myController.Status = ServiceProcess.ServiceControllerStatus.Stopped Then
        txtNum.Text = "Stopped"
    End If
End Sub
Private Sub Test_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Na1()
    ed()
End Sub
Private Sub Test_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
    Me.Refresh() '////////This one is not required
End Sub

Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
    ProgressBar1.Value = 0
    Try
        myController.Start()
    Catch ex As Exception
        MsgBox(ex.Message) 
    Finally
        ProgressBar1.Value = 100
        Na1()'//////////////////////////////////////////////Edit Code here
    End Try
End Sub

Private Sub txtNum_TextChanged(sender As Object, e As EventArgs) Handles txtNum.TextChanged
    ed()
End Sub

Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
    ProgressBar1.Value = 0
    Try
        myController.Stop()
    Catch ex As Exception
        MsgBox(ex.Message)
    Finally
        ProgressBar1.Value = 100
        Na1() '//////////////////////////////////////////////Edit Code here
    End Try
End Sub

您需要停止 SQL 服务来复制 .mdf 文件,Stopping/Starting 从 'Services' 手动服务非常烦人,所以我尝试使用 Vb.Net编码...

编辑以下代码,

Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
ProgressBar1.Value = 0
Try
    myController.Start()
Catch ex As Exception
    MsgBox(ex.Message) 
Finally
    ProgressBar1.Value = 100
    Na1()'//////////////////////////////////////////////Edit Code here
End Try
End Sub

Private Sub btnStart_Click(sender As Object, e As 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
        Na1()
    End Try
End Sub

Private Sub btnStop_Click(sender As Object, e As EventArgs) Handles btnStop.Click
ProgressBar1.Value = 0
Try
    myController.Stop()
Catch ex As Exception
    MsgBox(ex.Message)
Finally
    ProgressBar1.Value = 100
    Na1() '//////////////////////////////////////////////Edit Code here
End Try
End Sub

Private Sub btnStop_Click(sender As Object, e As 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
        Na1()
    End Try
End Sub

一切都完成了!