Monday, February 12, 2007

Import Mass Data to CRM 3.0: Unable to connect to the remote server

If you have mass/bulk data to be imported which is a custom entity in Microsoft CRM 3.0, there is no other better way, rather than built your own application. By default, CRM 3.0 only provide Bulk Import for Account, Contact and other several system entities (if any). Good luck if you have a lot of custom entities that is not possible to use built-in Bulk Import.

And I am not lucky that my project has quite a lot variety of data to be imported to CRM which is a custom entity. So, I have to built my own application to mass import the data. The application I have built have several basic function, like mapping between excel column and CRM attribute, lookup entity through different attribute, some validation, save/load settings, etc. If I got time, I hope I can tell more about this application in next post. After all seems ok, time to run the real data migration comes. And another unlucky thing happens that after importing about 1000+ records, CRM seems rejecting connection. The specific error is: "The underlying connection was closed: Unable to connect to the remote server". So, no matter what, I have to find a way to solve this problem. It's impossible for me to import every 1000 records for 1.5 million records. First, I try to set some thread sleeping time, or delaying inserting record for several second after several records, no luck. Second, I try to reset the connection by reinitializing the CRM Service, no luck. At last, I ask my uncle Google, and find really good and relevant Knowledge Base, the almighty "913515". If you are not Microsoft Partner, you won't be able to access this, but I think, if you develop Microsoft CRM, you are a Microsoft Partner. But, the point is to set the registry for MaxUserPort and set TcpTimedWaitDelay in HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Tcpip\Parameters (they are new registry key value). The maximum value for MaxUserPort is 65,534 (recommended 30,000) and TcpTimedWaitDelay is 260. If you face the same problem and unable to solve it, just contact me. :)

Wednesday, February 07, 2007

MS CRM 3.0: Callout's Configuration

As you know that you won't be able to use configuration settings from web.config, since Callout is executed inside CRM 3.0. I am not sure how the execution of Callout, but I suspect it's still under w3wp process, but it's already handled by CRM 3.0 execution and we are not able to use common function in ASP.NET. It's a common requirement that we need to put some configuration like connection string in some xml file, and it's common practice that this configuration is not hardcoded. So, how do you store and access this configuration. Here I share what I have done for my existing solution:

Create one xml file, for example custom.config, and copy this file to the same directory as your callout library:

<configuration>
<connectionstring>your connection string</connectionstring>
</configuration>

You can access the value of Connection String by writing this code in your callout:
XmlDocument doc = new XmlDocument();
string path = System.Reflection.Assembly.GetCallingAssembly().Location + + @"/custom.config";
doc.Load(path);
// set XPath to point to ConnectionString Node
XmlNode node = doc.SelectSingleNode("//Configuration/ ConnectionString");
string connString = node.InnerText;

If you have more than one configuration, you can add new node inside <configuration> and set the XPath in the code accordingly. Happy configuring!