I was working on a program to import thousands of records in CRM when this issue first appears in front of me.
This is typically seen in scenarios with Microsoft CRM when the server is under high user load or more typically when it is under high load from a Bulk import or a Microsoft CRM SDK application that is importing thousands of records into the application.
what I was doing :The same user and CRM Service was re-used for all calls after successfully working for some time it stops and this error appears “The Underlying connection was closed: Unable to connect to the remote server” this error is a problem due to running out of TCP ports. You can minimize or eliminate this problem by setting the following registry keys on the Microsoft CRM Server(s).
What this means is that we now have a total of 65534 TCP ports available and that they will recycle for use again after 30 seconds. This compares to the default of 5000 ports and a TcpTimedWaitDelay default of 240 (4 min).