Thursday, February 3, 2011

The Underlying connection was closed: Unable to connect to the remote server

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).  

Note that these are both REGDWORD Keys and the values should be set as decimal values.


Create a new REGDWORD value named MaxUserPort with a value of 65534.  

Also create a new REGDWORD value named TcpTimedWaitDelay with a value of 30.

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).

enjoy :-)

No comments: