I have recently become aware of this issue: https://blogs.msdn.microsoft.com/spike/2008/09/17/nested-recordset-and-the-portsocket-in-time_wait-problem-by-example/
Where if you open a recordset, then use the connection for something else with the recordset still open, the web server opens a new port to talk to the DB, then immediately puts that port into the TIME_WAIT state.
I have been going through the site to fix this (by closing recordsets before the connection is re-used - it works) but noticed something odd.
When the page has a "Response.Flush" on it, no matter WHAT you do, it causes an extra port to be used and then be put into the useless TIME_WAIT state. This can lead to a serious case of port exhaustion.
<%@ Language=VBScript %>
set cnn = server.CreateObject("adodb.connection")
cnn.open [YOUR CONNECTION STRING]
set rs=cnn.execute("select top 1 * from [YOUR TABLE]")
To check for time waits you can run:
netstat -nao | find /i "[YOUR DB IP]"
via the command prompt on the web server. Assuming this is a test system, you should immediately see time_wait connections popup from your web server to your DB server. Remove the flush, and this stops.
Googling has not helped - open to any suggestions.