How to restart the SQL Server service and computer through SQL Server

Source: Internet
Author: User
Tags mssqlserver

Yesterday I talked to my friends online about the application of SQL statements. My friend's remote server was unable to connect. The problem was that the remote server reached the maximum number of connections. In order to enable remote restart, I thought of using SQL statement commands to implement this function, but I forgot the specific command format. I found some information and wrote the method below,

Hope you can give me some help.

First, create a restart script on the local computer.
Copy codeThe Code is as follows:
Declare @ o int, @ f int, @ t int, @ ret int
Exec sp_oacreate 'scripting. filesystemobject ', @ o out
Exec sp_oamethod @ o, 'createtextfile', @ f out, 'c: \ restart. bat', 1
Exec @ ret = sp_oamethod @ f, 'writeline ', NULL, 'net stop mssqlserver'
Exec @ ret = sp_oamethod @ f, 'writeline ', NULL, 'net start mssqlserver'

Connect to the remote server through SQL database -- execute the restart script
Exec master .. xp_mongoshell 'C: \ restart. bat'

/*
If you restart the computer, make sure that the mssqlserver account runs under the Administrator account (non-local SYSTEM account)

*/

Exec master .. xp_mongoshell 'shutdown/r/F'

There is a premise that a component on the server, xp_mongoshell, needs to be used, but the general server,

This component is disabled. Therefore, you must first use the component to apply the above method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.