How to stop/start service using T-SQL?

  • I have problem in stoping or starting service application using T-SQL.

    Does anyone in this forum know the way to do that?

    Thanks in advance

    Regards,

    Eko Indriyawan

  • You can shutdown SQL Server using T-SQL, look up the SHUTDOWN command in Books Online. Once the service is stopped, you have no way of running any commands when SQL Server is down - so there is really no way to start the service up using T-SQL.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Hi Jeffrey Williams,

    Thanks for your replies.

    Maybe my question is so strange.

    But I can do it based on command prompt using XP_CMDSHELL

    ex:

    XP_CMDSHELL 'SC CONFIG MSDTC START= AUTO'

    GO

    XP_CMDSHELL 'SC START MSDTC'

    GO

    for more information: http://technet.microsoft.com/en-us/library/cc990290%28nl-nl,WS.10%29.aspx

    Regards,

    Eko Indriyawan

  • In order to be able to use xp_cmdshell - you have to connect to SQL Server. If SQL Server has been shut down, there is nothing for you to connect to.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • You're right.

    I need this command to create installer of my product.

    1. Installer install MS SQL Server

    2. Installer start the service when the service of MS SQL Server not start

    3. Installer start another service using T-SQL, I do this because the service is not mine, so I just to call it using command

    4. Installer install my application

    5. Finish

    SO, I need this command just for a while

    Maybe you have suggestion for me?

    Thanks in advance

    Regards,

    Eko Indriyawan

  • Nope, sorry - still can't change the fact that you cannot use T-SQL to start SQL Server. You have even more problems though...

    1) What are you going to do if SQL Server is already installed?

    2) If it is already installed, are you sure you want to stop and start the service?

    3) Stopping/Starting a third-party service that already exists? Why would you need to restart that service? Nothing you do should have any effect on a service you do not own.

    If you are building an installer - you will be running it from the OS, why are you trying to run OS level commands from within SQL Server? Sorry, this just doesn't make sense...

    And finally, if you are installing into a pre-existing instance of SQL Server you probably will not have access to xp_cmdshell at all, as that is usually not enabled in SQL Server by default.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • Thank you very much for your suggestions.

    I use InstallAware to build installer, InstallAware can config the service only the service that we've created.

    It can not config the service that already install into OS, but can start/stop it. So, I have to look for the solution for config the service that already install, for example msdtc.

    We know that MSDTC already install and but start on demand. I don't want to start in manually from services application manager, I want installer can do that.

    Btw, what have I done seemly so strange.

    Once again, thank for your explanation.

    King Regards,

    Eko Indriyawan

  • eko indriyawan (1/24/2010)


    ...

    I use InstallAware to build installer,

    ...

    In that case you might be better off asking your question in the InstallAware forums.

  • Thanks for your suggestion.

    Regards,

    Eko Indriyawan

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

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