How to Restart /shutdown Database Server From VB

  • Hi, I want to restart the server machine thru my VB application. Before that I want to shutdown the database server running in the same machine, again from my VB application. How do I do this.

    Request a reply ASAP

    Regards,

    Harsha

    HArsha


    HArsha

  • I'm pretty sure you'll find a method in the SQL-DMO API.

    Have you searched this site?

    Frank

    http://www.insidesql.de

    http://www.familienzirkus.de

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • Have you considered net stop and net start commands?

    Jeremy

  • yes, both this ways exists !!

    net stop MSSQLServer

    and

    objSQLServer.Shutdown ( TRUE ) -- for normal shutdown

    objSQLServer.Shutdown ( FALSE ) -- for immediate shutdown


    -- Amit



    "There is no 'patch' for stupidity."



    Download the Updated SQL Server 2005 Books Online.

  • Thanks for the replys. I have searched in the site. But I did not find any good answer.

    Net Stop I have seen in the help. Ihave some doubts about it

    1. Itruns only in command prompt using osql. Isnt't? So we need to write a batch file with this command and run the bat file from VB.

    2. It shuts down only the instance which we pass to the command, isn't it. So do I need to run this command for each sessions. Or is it talking about the server instance only, ie. with one command , it shuts down the system?

    3. Is there any other way to do the same instead of using osql. But running any commands using ADO in Vb

    Thanks again for the fast replys

    Regards,

    Harsha

    HArsha


    HArsha

  • 1. NET STOP is a Windows OS command & not a TSQL command. so you have to run it from a command prompt or bacth file.

    2. ADO can shutdown SQL Server instance, but can not bring it up !!!!

    3. Shutdown is a process for server & not for individual user sessions. When a shutdown occours, all user processes are rollbacked & terminated by server.

    I hope this solved your questions.


    -- Amit



    "There is no 'patch' for stupidity."



    Download the Updated SQL Server 2005 Books Online.

  • To shutdown/reboot machine, try:

    
    
    Set colOperatingSystems = GetObject("winmgmts:{(Shutdown)}").ExecQuery("Select * from Win32_OperatingSystem")
    For Each objOperatingSystem in colOperatingSystems
    ObjOperatingSystem.Win32Shutdown(6)
    Next
    ObjOperatingSystem.Win32Shutdown(6)
    '6=forced reboot. Change to 12 for forced power off.

    See http://www.dandinicolo.com/article.aspx?articleID=280&page=5 for more info, or do search on "win32shutdown".

    Bill

  • You can use this API function

    Public Declare Function StartService Lib "advapi32.dll" Alias "StartServiceA" (ByVal hService As Long, ByVal dwNumServiceArgs As Long, ByVal lpServiceArgVectors As Long) As Long

    quote:


    Hi, I want to restart the server machine thru my VB application. Before that I want to shutdown the database server running in the same machine, again from my VB application. How do I do this.

    Request a reply ASAP

    Regards,

    Harsha

    HArsha


  • You can use this API function

    Public Declare Function StartService Lib "advapi32.dll" Alias "StartServiceA" (ByVal hService As Long, ByVal dwNumServiceArgs As Long, ByVal lpServiceArgVectors As Long) As Long

    quote:


    Hi, I want to restart the server machine thru my VB application. Before that I want to shutdown the database server running in the same machine, again from my VB application. How do I do this.

    Request a reply ASAP

    Regards,

    Harsha

    HArsha


Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply