|
|
|
Using the SQL-DMO object model you can programmatically start, stop, pause, and continue the main SQL Server service. In the following code snippet the server is "MyServer", and "sa" / "mypwd" is the user name and password of a user that is allowed to start/stop the service: |
Click here to copy the following block | ' NOTE: this code assumes that you've added a reference to the ' SQL-DMO type library in the References dialog box
' start, pause, continue and stop SQL Server service Dim SQLServer As New SQLDMO.SQLServer
' starting the service requires that you specify ' the server's name and user credentials SQLServer.Start False, "MyServer", "sa", "mypwd"
' pausing, continuing and stopping the service ' doesn't require any additional argument SQLServer.Pause SQLServer.Continue SQLServer.Stop |
You can also test the current state of the SQL Server service by means of the Status property: |
Click here to copy the following block | ' show current state of the service Select Case SQLServer.Status Case SQLDMOSvc_Paused: lblStatus = "Paused" Case SQLDMOSvc_Running: lblStatus = "Running" Case SQLDMOSvc_Starting: lblStatus = "Starting" Case SQLDMOSvc_Stopped: lblStatus = "Stopped" End Select |
Finally, you can programmatically enable or disable the autostart feature (that is, the capability to run the SQL Server service automatically when the system reboots): |
|
|
|
Submitted By :
Nayan Patel
(Member Since : 5/26/2004 12:23:06 PM)
|
|
|
Job Description :
He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting. |
View all (893) submissions by this author
(Birth Date : 7/14/1981 ) |
|
|