Starting SQL Server 2012 services in Visual Basic 2013

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MickT
    New Member
    • Feb 2007
    • 28

    Starting SQL Server 2012 services in Visual Basic 2013

    I am using SQL Server 2012 Developer edition and Visual Studio 2013

    Code:
    Imports System.ServiceProcess (also included in project.references)
    
    Dim service As New ServiceController("MSSQLSERVER") ' For checking status of SQL Server & starting if necessary
    
    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
    I get the error message that the application can't start the service on my computer.

    I've also tried running a .bat file containing NET START Servicename as a shell; it runs but doesn't start the services

    My MSSQLSERVER and SQL Server Agent services are set to start Automatically, but they don't alsway start, which is why I want to test their status, and then start them if necessary.

    Has anyone any ideas how to resolve this problem
    Last edited by Rabbit; Feb 8 '16, 05:41 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • MickT
    New Member
    • Feb 2007
    • 28

    #2
    I hope that's all right now.

    Comment

    Working...