Remote Control Database Utility SQL Restart function

Source: Internet
Author: User
Tags mssqlserver

The remote server reached the maximum number of connections, in order to achieve remote restart, so think of the SQL Statement command to implement this function, but the specific command format to forget, found a bit of information tutorial . net/c# Course [4]:sqlserver Basic application Development , Write the method below, hope can give you some help it, hehe.

First on the local computer--Create a restart script
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 via SQL database--performing a restart script
exec master. xp_cmdshell ' C:/restart.bat '
/*
If you restart your computer, make sure that the MSSQLServer account is running under the Administrator account (not the local System account)
*/
exec master. xp_cmdshell ' shutdown/r/F '
Here is a premise, it is necessary to use a component on the server, xp_cmdshell this component, but the general server,
this component is disabled. Therefore, you must first use the component before you can apply the above method.

Remote Control Database utility SQL Restart function

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.