IIS Express-The Specified Port Is In Use

So you’re in the zone, been coding all day, have all tools in just the right spot.  Then BAM!  The dreaded port is in use.

Port is in use error image

Reading about this issue on stack overflow some people say its been chrome that has the port, or sometimes another process.  For me, It’s always some orphaned or hung IIS Express process holding onto the port.  Rarely, trying to start the debugger again will let you continue, but most of the time I had to resort to a reboot.  This is obviously inconvenient and a waste of time.  So here’s another option. 

Get PS Kill

The PS Tools are awesome you should check them out.  All we need today is PSKill.  Install/Extract is as you see fit and make sure you can access it from the command line. 

Netstat knows who is using the port

Run this from the command line.

netstat –ano | findstr <port> (in this case netstat –ano | findstr 62646)

The n is really important.  It prevents trying to resolve all the DNS names of the ip addresses you have connections to.  Without it, this command is so slow, it may appear broken.

Your should get one results like this.  

TCP    0.0.0.0:62646       D2000:0                LISTENING       2076

What your looking for is the number at the end of the line.  It’s the PID of the process that currently has the port open.

Use PS Kill

Once you know the PID of the process you need to kill you can use pskill to stop it. 

Open an administrative command prompt, then run pskill <pid> (in this example pskill 2076)

Note: On very rare occasions you will see a PID or 0 or 1 (I forget off the top of my head.  This is the NT system process.  I do not recommend trying to kill it)