Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

GENERIC SQL Error when using custom relationship SDK endpoint

Posted on by Microsoft Employee

We have done a great deal of customization and development to support our Firm's on-premise implementation of Dynamic CRM.

We have had a few pitfalls, however our current issue is quite confusing.

We have created a custom entity (ClientMatter).

We have created a custom many to many relationship between this ClientMatter entity and the Contact entity (firm_clientmatter_contact_MM).

We have created a second custom many to many relationship between this ClientMatter entity and the Account (company in our world) entity (firm_clientmatter_company_MM).

Using the API endpoint the following requests work without any issue:

http:// .... /api/data/v8.0/firm_clientmatters  (all client matters in the system)

http://..../api/data/v8.0/firm_clientmatters(xxxxx-xxxxxx-xxxxxx-xxxx)   (one specific client matter)

http:// ... /api/data/v8.0/firm_clientmatter_contact_mmset  (list of all relationships between clientmatters and contacts)

http:// ... /api/data/v8.0/firm_clientmatter_company_mmset  (list of all relationships between clientmatters and companies)

http://..../api/data/v8.0/firm_clientmatters(xxxxx-xxxxxx-xxxxxx-xxxx)/firm_clientmatter_company_MM  (complete record list of all companies connected to a specific clientmatter)

XXXXXXXXXXXXXXXXXXX HERE IS THE PROBLEM XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The following URL only works if the calling user has System Admin privileges:

http:// .... /api/data/v8.0/firm_clientmatters(XXXXXXXX-XXX-XXX-XXXXXXXXX)/firm_clientmatter_contact_MM (complete record list of all contacts connected to a specific clientmatter)

If the user does not have admin privileges they receive a 500 code and the following error:

{
"error":{
"code":"","message":"Generic SQL error.","innererror":{
"message":"Generic SQL error.","type":"System.ServiceModel.FaultException`1[
[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35]]","stacktrace":" at
Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.
Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken
callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode,
ExecutionContext executionContext)\r\n
at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Execute(OrganizationRequest request)\r\n
at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEntityWithRelatedRecords(CrmODataExecutionContext
context, EntityReference primaryEntityReference, QueryExpression qe, RelationshipQueryCollection relatedEntitiesQuery)\r\n
at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.RetrieveEdmEntityNavigation(CrmODataExecutionContext context,
String edmEntityName, String entityKeyValue, String navigationPropertyName, ODataQueryOptions queryOptions, Boolean onlyRef)\r\n
at Microsoft.Crm.Extensibility.OData.EntityController.GetNavigationInternal(String entityName, String key, String navigation,
String derivedNavigation, Boolean isMetadataEntity, CrmODataExecutionContext context, ODataQueryOptions queryOptions,
CrmEdmEntityObjectCollection crmEdmEntityObject)\r\n
at Microsoft.Crm.Extensibility.OData.EntityController.GetNavigation(String entityName, String key, String navigation)\r\n
at lambda_method(Closure , Object , Object[] )\r\n
at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[]
methodParameters)\r\n at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext,
IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n---
End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n---
End of stack trace from previous location where exception was thrown ---\r\n
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
}
}
}

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

To further confuse things, the previous version of the CRM endpoints work with the following query regardless of user priveledges:

http:// .....   /CRM/XRMServices/2011/OrganizationData.svc/firm_clientmatterSet(guid'XXXX-XXXX-XXXXX-XXXXXXX')/firm_clientmatter_contact_MM

but of course this only returns 50 records per call.

There are ways to code around this, but in order to maintain our coding standards and structure we would like to get this to work properly.

Any assistance will be greatly appreciated.

*This post is locked for comments

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans