• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 464
  • Last Modified:

How to restart sql server services using script ?

Please let me know how to restart SQL Server Services using script ?
0
PKTG
Asked:
PKTG
2 Solutions
 
Coralie CrumrineCommented:
Using .NET here is the code I use in VB
Imports System.ServiceProcess.ServiceController '//Used to stop/start service



Try
            Dim controller As New ServiceProcess.ServiceController

            '//Specify local machine
            controller.MachineName = "."

            '//Specify service name
            controller.ServiceName = szServiceName

            '//Stop the service
            controller.Stop()

            '//Wait until the status is stopped
            controller.WaitForStatus(ServiceProcess.ServiceControllerStatus.Stopped)

            '//Start the service
            controller.Start()

            '//Wait until the service is running again
            controller.WaitForStatus(ServiceProcess.ServiceControllerStatus.Running)

            '//If get here, all is good
            Return True
        Catch ex As Exception
            RptError("Unable to restart the service!", ex)
            Return False
        End Try

Open in new window

0
 
k_murli_krishnaCommented:
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now