How to restart SQL Server services and computers via SQL Server _mssql

Source: Internet
Author: User
Tags mssqlserver
Yesterday and friends on the Internet talking about the application of SQL statements, my friend's remote server appears to be unable to connect the phenomenon, the problem is due to the remote server reached the maximum number of connections, in order to achieve remote reboot, so that the use of SQL Statement command to implement this function, but the specific command format to forget, find some information, Write the method down below,

I hope we can give you some help, hehe

First on the local computer--Create a restart script
Copy Code code 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 '

Connecting to a remote server through a SQL database--performing a restart script
EXEC master.. xp_cmdshell ' C:\restart.bat '

/*
If you restart your computer, confirm that the MSSQLServer account is running under the Administrator account (non-local System account)

*/

EXEC master.. xp_cmdshell ' shutdown/r/F '

Here is the premise, that is, need to use a component on the server, xp_cmdshell this component, but the general server,

This component is disabled. So you have to use the component before you can apply the above method.
Related Article

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.