Use xp_cmdshell to log off Windows Logged-in users (Terminal Server exceeds maximum number of connections) _mssql

Source: Internet
Author: User
Company daily project update using TFP, server general maintenance with Remote Desktop management, so often log on to the server, but sometimes for some reason, login to the server, the account did not log off in time, resulting in the following can not log on to the server,

Display errors such as

This problem is really troublesome, run the machine room light formalities must be two or three days to do well. Fortunately, the company has been keeping the SA account,

This is easy to do, log off a Windows logged-on user with SQL.

First Open xp_cmdshell
--Execute xp_cmdshell to open xp_cmdshell
EXEC sp_configure ' show advanced options ', 1
Reconfigure with OVERRIDE
Reconfigure
EXEC sp_configure ' xp_cmdshell ', 1
Reconfigure with OVERRIDE
Reconfigure

View current Windows Logged-in users

EXEC xp_cmdshell ' query user '

Logoff administrator user with ID 2
EXEC xp_cmdshell ' Logoff 2 '

--Close xp_cmdshell
EXEC sp_configure ' xp_cmdshell ', 0
Reconfigure with OVERRIDE
Reconfigure
EXEC sp_configure ' show advanced options ', 0
Reconfigure with OVERRIDE
Reconfigure

Ok, done, and can be Remote Desktop.

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.