Command Line Hack for: "Terminal Server Has Exceeded the Maximum Number of Allowed Connections"
If you've worked on a network with Windows servers, you've encountered this error message at least 37,000 times:
"The terminal server has exceeded the maximum number of allowed connections. The system can not log you on. The system has reached its licensed logon limit. Please try again later."
This problem happens because Windows only allows two remote terminal services connections when you are in administrative mode, and you've either got two people already on that server, or more likely, you've got a disconnected session that still thinks it is active.
The problem with this error is that you have to actually get on the server console to fix the problem if the server isn't in a domain. (If you are in a domain, then just open Terminal Services Manager and log off or disconnect the sessions)
To use the command line hacks, you might need to run them from another server if your local operating system doesn't include the commands. You will also need to make sure that you are logged onto that server with an administrative account. The easiest way to do that is just map a drive (you don't have to use a drive letter unless you choose to)
net use /user:[username] \\servername\share
Here's a command line hack that you can use to figure out what sessions are connected to the server. Note that you could substitute the IP address for the server name.
query session /server:servername
Sample output:
Now we know that the session ID of the offending session is 2. We can use that in the next step, which is using the reset command to log off that user.
reset session [ID] /server:servername
Sample:
This command won't display any output, but when we run the query command again, we should see that the session has now been disconnected:
Note: Thanks to my friend Todd for this one.


Great help for me to identify this command
That is a great tip. I usually just use "mstsc /v:servername /console" to connect to the console session, and then I can close the bad sessions.
Another tip, if you have sql server and have enabled xp_cmdshell you can use these same tips via query analyser.
Very good solution for such a problem.
Thanks for sharing such command lines.
Thanks! It saved me a trip to the data center!
Hi Folks,
I really do run into this problem about "37000″ times a week. This solution is a life saver.
Thanks a bunch!
Wayne
Cool solution mate.
Thanks!
Just hit bed and got a call from a customer about this. You saved my night of sleep.
Or…
Just type in tsadmin in the run or command prompt, connect to the server in question, and disconnect, reset, or log off the offending/stale session.
Thanks for this solution. Excellent.
You saved from going to dc's control panel, and rebooting my server each time i have this issue.. Thanks
Hi
My fellow geeks i'm a white South-African and this line just saved my ass from being fired at work.
THANKS A LOT !!!!!
Thanks. That saved me a lot of hassle.
Awesome, guys! It is such a needed tip!
When i type in the commands, my XP Pro cmd tells me query is not recognized
Any idea why?
Great, it saved our life at 12:00 am, we have a migration work on production and got this error, your article saved us. Thanks
Hi,
This tip is really very very useful. It has helped my Data migration, restore and backup
Thanks, It worked like charm.
Excellent tip. Much more useful than the "Start -> Run -> mstsc -v:x.x.x.x /console" tip that is floating around the Net. Our systems use specific admin users and I would've had to figure out how to login to the relevant server from my Mac, in my Windows VM image, as a normal user, using "Run As…", to launch the console on the server… just too much when I needed it.
By contrast, your tip explained the need to get onto another server having the tools, and the exact commands to use and output to expect. Neat, concise, and working. Thanks.
When using Administrative mode, Windows Server 2003 allows 2 concurrent connections plus a console connection. To access the console connection, type mstsc /console from Start->Run.