FetchXML query not working in CRM 2011 RRS feed

  • Question

  • I have a custom entity in Dynamics Crm and I am using a fetchXml query to retrieve the count of records that fulfill a specified condition. My query was working fine in Crm 4.0 Online. After we upgraded to the Crm 2011 Online, the query is now throwing a SoapException with a "Generic Sql error" message. The query that I am using is as follows:

    <fetch mapping='logical' aggregate='true'>");
    <entity name='my-custom-entity-name'>
    <attribute name=my-primary-key-attribute' alias='Count' aggregate='count'/>
                <filter type='and'>
    <condition attribute='my-lookup-type-attribute' operator='eq' value='some-guid'/>

    In this query, I am just counting the number of records that relate to another custom entity. Moreover, I am using the CrmService's Fetch method to query the Crm. Any help in resolving this error would be greatly appreciated.

    Tuesday, April 19, 2011 12:41 PM

All replies

  • Hello,

    You can use this CRM 2011 JavaScript library for your scenario: http://www.bizforward.cws-international.com/2011/03/09/useful-javascript-functions-and-methods-for-crm-2011-cws-crm-utils-js-library/.

    Cornel Croitoriu - Senior Software Developer & Entrepreneur

    If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"


    Wednesday, April 20, 2011 7:24 AM
  • Thanks for your reply Cornel, but I dont think this javascript library will be of much use to me. I am just looking for an explanation of what might be wrong with my query syntax which was working fine in Crm 4.0
    Wednesday, April 20, 2011 11:17 AM
  • This is a basic query and it should work in 2011.

    Can you try the following query using Account entity. Also try removing the filter condition or add some other attribute to the filter.


    Nabanita Majumdar

    Thursday, March 29, 2012 10:48 PM
  • If you get a Generic Sql Error, then the query syntax is valid, but there is a problem at the SQL end.

    Unfortunately CRM Online won't allow you to investigate this at the SQL level, but the most likely considerations are:

    • There could be a query timeout. How long does it take before you get the error. If it's 30 seconds or more, then the problem is likely to be a timeout
    • The next possible cause is lock contention (probably deadlocks). In this scenario I'd expect the error to come a lot sooner. This is most likely if you're executing the query within a synchronous plugin, and maybe having a conflict with the transaction that caused the plugin to fire, and is modifying the data.

    Microsoft CRM MVP - http://mscrmuk.blogspot.com  http://www.excitation.co.uk

    Friday, March 30, 2012 6:52 AM