Error While inserting large number of Invoice Products into Invoice entity
-
Friday, May 04, 2012 2:38 PM
Hi guys,
I am importing data from DB2 to CRM online. its working fine if the number of invoice products are less. But sometimes we have 5000 invoice products also. while inserting large number of invoice products to invoice entity we are getting the following errors.
SQL timeout expired,
Generic SQL error,
The underlying connection was closed: The connection was closed unexpectedly.
Appreciate your help. Thanks
ravindra
All Replies
-
Friday, May 04, 2012 5:53 PM
Here is a helpful blog on CRM 2011 timeout settings.
However the bigger picture might be how you are doing the import...what approach are you using to import the data? You may need to split the invoice product insert across transactions if you are hitting timeouts.
- Proposed As Answer by Neil BensonMVP, Moderator Friday, May 04, 2012 11:15 PM
-
Friday, May 04, 2012 6:17 PM
Dear Ken,
We are using Biztalk Server as a middle ware to import data.
Here we created proxy class for https://dentsplybeneluxtest.api.crm4.dynamics.com/XRMServices/2011/Organization.svc and we are using c# code. Here is the code
Invoice
inv = newInvoice();
inv.Name = invoice.InvoiceNumber +
" : "+ invoice.InvoiceDate + " : "+ optionSetList[invoice.ERPCompanyName];
inv.CustomerId = erAccount;
inv.dnt_ERPBillToCustomerNumberId = erCustomer;
inv.dnt_ERPCompanyName = os;
inv.dnt_ERPInvoiceNumber = invoice.InvoiceNumber;
inv.TransactionCurrencyId = erCurrency;
inv.PriceLevelId = erPriceList;
DateTimedt = DateTime.Parse(invoice.InvoiceDate.Substring(4, 2) + "-"+ invoice.InvoiceDate.Substring(6, 2) + "-"+ invoice.InvoiceDate.Substring(0, 4));
inv.dnt_InvoiceDate = dt;
inv.dnt_InvoiceYear =
Int32.Parse(invoice.InvoiceYear);
inv.dnt_InvoicePrefix = invoice.InvoicPFX;
EntityCollectionecProducts = newEntityCollection();
ecProducts.EntityName =
InvoiceDetail.EntityLogicalName;
foreach(InvoicesInvoiceInvoiceProductinvProduct ininvoice.InvoiceProduct)
{
InvoiceDetailiProd = newInvoiceDetail();
iProd.dnt_AccountId = erAccount;
iProd.dnt_ERPBillToCustomerNumberId = erCustomer;
iProd.dnt_ERPCompanyName = os;
iProd.dnt_ERPInvoiceNumber = invoice.InvoiceNumber;
iProd.dnt_InvoiceDate = dt;
QueryExpressionqeProduct = newQueryExpression();
qeProduct.EntityName =
"product";
qeProduct.ColumnSet =
newColumnSet("productid", "productnumber");
ConditionExpressioncon = newConditionExpression();
con.AttributeName =
"productnumber";
con.Operator =
ConditionOperator.Equal;
con.Values.Add(invProduct.Product);
FilterExpressionfil = newFilterExpression();
fil.FilterOperator =
LogicalOperator.And;
fil.Conditions.Add(con);
qeProduct.Criteria = fil;
EntityCollectionecItem = _serviceProxy.RetrieveMultiple(qeProduct);
EntityReferenceerProd = newEntityReference();
EntityReferenceerUnit = newEntityReference();
EntityReferenceerPClass = newEntityReference();
if(ecItem.Entities.Count > 0)
{
erProd.Id =
newGuid("{"+ ecItem.Entities[0]["productid"].ToString() + "}");
iProd.ProductId = erProd;
}
else
{
thrownewException("Product does not exist");
}
erUnit.Id =
newGuid("{"+ unitList[invProduct.Unit] + "}");
iProd.UoMId = erUnit;
if(productClassList.AllKeys.Contains(invProduct.ItemClass))
{
erPClass.Id =
newGuid("{"+ productClassList[invProduct.ItemClass] + "}");
}
else
{
erPClass.Id =
newGuid("{"+ GetProductClassBasedOnProductClassName(invProduct.ItemClass) + "}");
}
iProd.dnt_ProductClassId = erPClass;
iProd.Quantity =
decimal.Parse(invProduct.Quantity);
Moneymoney = newMoney();
money.Value =
decimal.Parse(invProduct.Price);
iProd.PricePerUnit = money;
iProd.IsProductOverridden =
false;
iProd.IsPriceOverridden =
true;
ecProducts.Entities.Add(iProd);
}
inv.RelatedEntities.Add(
newRelationship("invoice_details"), ecProducts);
_serviceProxy.Create(inv);
ravindra