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.