Troubleshooting "Generic SQL error" in CRM web api + fetchxml query
Views (2727)
I was constructing a fetchxml query to use in web api call, while doing a browser test itself it failed. The error message is as usual "Generic sql error".
Nothing special in that query. Its a simple query but its going to be complex in further iterations.
So the error message gives me some useful information. For example - Error code. But the piece that helped me to find out the problem is actually Sql Number: 421
This Database Engine Errors page talks about all the possible errors & am able to find the 421 issue as "The %ls data type cannot be selected as DISTINCT because it is not comparable."
Therefore the error is because of entityimage attribute I put in select list, though this fetchxml when used in web api is not giving us the binary content of that records' entityimage values - still distinct = "true" cannot be used along with entityimage attribute type per above error message.
Need to remove either distinct = "true" or <attribute name="entityimage" />. Then the problem is solved. :)
{
"error": {
"code": "0x80044150",
"message": " Sql error: Generic SQL error. CRM ErrorCode: -2147204784 Sql ErrorCode: -2146232060 Sql Number: 421",
"innererror": {
"message": " Sql error: Generic SQL error. CRM ErrorCode: -2147204784 Sql ErrorCode: -2146232060 Sql Number: 421",
"type": "System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",
"stacktrace": " at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.RetrieveMultiple(QueryBase query, InvocationContext invocationContext, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, Guid appModuleId,...........
Nothing special in that query. Its a simple query but its going to be complex in further iterations.
https://org.crm.dynamics.com/api/data/v9.0/leads?fetchXml=
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="true">
<entity name="lead" >
<attribute name="entityimage" />
<attribute name="leadid" />
<attribute name="fullname" />
<attribute name="ps_operatingsystemid" />
<attribute name="ps_rollup_assistants" />
<attribute name="ps_businesstitle" />
<attribute name="ps_specialtitle" />
<attribute name="emailaddress1" />
<attribute name="mobilephone" />
<attribute name="ps_globaldirtitle" />
<attribute name="ps_department" />
<attribute name="address1_city" />
<order attribute="fullname" descending="false" />
<filter type="and" >
<condition attribute="fullname" operator="like" value="%arun vinoth%" />
</filter>
</entity>
</fetch>
So the error message gives me some useful information. For example - Error code. But the piece that helped me to find out the problem is actually Sql Number: 421
This Database Engine Errors page talks about all the possible errors & am able to find the 421 issue as "The %ls data type cannot be selected as DISTINCT because it is not comparable."
Therefore the error is because of entityimage attribute I put in select list, though this fetchxml when used in web api is not giving us the binary content of that records' entityimage values - still distinct = "true" cannot be used along with entityimage attribute type per above error message.
Need to remove either distinct = "true" or <attribute name="entityimage" />. Then the problem is solved. :)
This was originally posted here.
*This post is locked for comments