Friday, June 01, 2007

CRM insert issue "Unable to connect to the remote server " ...force sleep

Hello – I was almost pulling out my hair with this CRM insert issue "Unable to connect to the remote server "… :)
I have written a small console based utility in net 2.0 … which tries to insert 7000 odd records (custom entity property records) into CRM. I am using CRM webservice to do this.

However, before inserting into CRM I am checking if property record already exists in CRM database or not. I am using "RetrieveMultiple" to search a particular property record and accordingly insert or update one in CRM.

Everything works fine if I run the utility from my computer (client computer) to populate the CRM Dev database but when I try to run this utility from the Dev server itself (through remote desktop connection) after loading 3000 odd records it keeps on failing at RetrieveMultiple() statement. The exception it shows is as below -

Error: --- > Unable to connect to the remote server

Stack Trace: ----- > at System.Net.HttpWebRequest.GetRequestStream()

at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)

at MS.Data.CrmWebService.CrmService.Create(BusinessEntity entity)

at MS.Integration.RIM.Program.PopulatePropertyEntity(CrmService crmService, Ratings retFR_Mobil)

Initially, I thought this would be occurring because of bad data but I figured that if I rerun the utility to start from 2999 again then it works fine again and stops randomly after loading 1000 odd records or so again.

So I was pretty confident that this may NOT be because of bad data! It also ran from my machine just fine.

So the question was "Does the CRM web service time out after few inserts"
Does CRM have limitations while inserting records quickly?

Solution - I tried doing a force sleep for 30 secs and it worked fine. For you if this doesn't work then try these steps -

This may also be caused by the number of ports available in IIS - every create method will be creating a new connection to the server, and after a certain period, all the available ports are used up and no new connections can be made.

I recommend looking at the article here on Performance [1] and setting the UnsafeAuthenticatedConnectionSharing on the CrmService to true. This *should* then only create one connection and re-use it for all your data inserts.


Credits to Rich for psting me on this. Rich you are the man! :)
HTH - Dipesh

No comments: