views:

42

answers:

2

Im having some trouble with Dynamics CRM 4. Im trying to update prices and availability with the crm-service in a WPF-app but it takes forever. Up to half an hour with about 6000 products. Should it take so long? Can I do this in some other quicker way?

QueryExpression query = new QueryExpression();
query.EntityName = EntityName.product.ToString();

BusinessEntityCollection entities = crmService.RetrieveMultiple(query);

foreach (product crmProduct in entities.BusinessEntities.OfType<product>())
{
  crmProduct.price = new CrmMoney() { Value = 123M };
  crmProduct.stock = new CrmNumber() { Value = 123 };
  crmService.Update(crmProduct);
}
A: 

Try setting this on your CRM Service object:

crmService.UnsafeAuthenticatedConnectionSharing = true;

This makes the service only authenticate once, then uses the same credentials. This would be a bad thing if the code were in a web site where multiple people were going to be using the same CRM Service, as future users could get access to records they shouldn't, however, in a WPF app where there's just one user, this isn't a concern.

Here's an article with more metrics and some more things to think about tweaking. It originally applies to CRM 3, but we've found the same settings in 4 still boost performance.

Matt
+1  A: 

To improve performance, try to update only the fields that you really wan to update. Your code is updating every attribute, because you are using the product that comes from CRM. When you are doing that every plugins are fired and because product is a core CRM entity, more CRM logic can be fired when updating this entity.

Try to get only the primary key of product (productid) and set both fields and call the update statement. With this, you should achieve about 100 requests per second on standard hardware when using a sequential process.

To achieve more updates, try running the process on the CRM server or using parallel processing.

Mercure Integration