添加机会产品时,CRM无法获得资源锁定



我在机会产品上有一个插件,计算项目创建或更新时的税收。大多数情况下,它工作得很好,但当我以编程方式添加一些产品时,它有时会失败,如下所示。

抛出异常时,新的机会产品存在于数据库中,并且它试图锁定的行是在它之前添加的行。我认为发生的事情是,我添加了一个新产品,然后CRM检索所有产品,以便有机会计算总数。我不知道用什么机制来更新总数。这不是一个普通的插件,我甚至没有办法看到它在做什么,更不用说改变它了。

这是包含rollup 15(v2)的CRM 2011的内部部署安装。

任何想法?

谢谢,比尔

Microsoft.Xrm.Sdk。SaveChangesException:处理此请求时发生错误。--> System.ServiceModel.FaultException 1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Cannot obtain lock on resource:'OpportunityProduct_dbe8cb25-031c-e411-8f23-002269c5d599', mode:Update - stored procedure sp_getapplock returned error code -3. Result StackTrace:
Server stack trace: at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc) at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout) at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation) at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message) Exception rethrown at [0]: at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) at Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest request) at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.ExecuteCore(OrganizationRequest request) at Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy.Execute(OrganizationRequest request) at Microsoft.Xrm.Client.Services.OrganizationService.<>c__DisplayClass19.<Execute>b__18(IOrganizationService s) at Microsoft.Xrm.Client.Services.OrganizationService.InnerOrganizationService.UsingService[TResult](Func
2 action)在Microsoft.Xrm.Client.Services.OrganizationService。执行(OrganizationRequest请求)在Microsoft.Xrm.Client.Services.CachedOrganizationService。InnerExecute (OrganizationRequest请求)在Microsoft.Xrm.Client.Services.OrganizationServiceCache。InnerExecute[TRequest,TResponse, result](TRequest query, Func 2 execute, Func selector)在Microsoft.Xrm.Client.Services.OrganizationServiceCache。InnerExecute[TRequest,TResponse, result](TRequest request, Func 2 execute, Func 2 selector, String selectorCacheKey)在Microsoft.Xrm.Client.Services.OrganizationServiceCache。执行[T](OrganizationRequest请求,函数2 execute, Func选择器,字符串selectorCacheKey)在Microsoft.Xrm.Client.Services.CachedOrganizationService。执行[T](OrganizationRequest请求,函数5 execute, Func 2选择器,字符串selectorCacheKey)在Microsoft.Xrm.Client.Services.CachedOrganizationService。执行[T](OrganizationRequest请求,函数2 selector, String selectorCacheKey) at Microsoft.Xrm.Client.Services.CachedOrganizationService.Execute[T](OrganizationRequest request) at Microsoft.Xrm.Client.Services.CachedOrganizationService.Execute(OrganizationRequest request) at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request) at Microsoft.Xrm.Client.CrmOrganizationServiceContext.Microsoft.Xrm.Sdk.IOrganizationService.Execute(OrganizationRequest ) at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request) at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChange(OrganizationRequest request, IList 1结果)——内部异常堆栈跟踪结束——在Microsoft.Xrm.Sdk.Client.OrganizationServiceContext。SaveChanges (SaveChangesOptions选项)在Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges ()在RenewalUnitTests.CrmTest。CreateProposalServiceCode(Guid proposalId,字符串servicecodennumber,字符串servicePeriodNumber,字符串servicePeriodNumber2, Int32数量,字符串uomName)在c:Codektfs1ProjectsCRMDEV renew RenewalUnitTestsCrmTest.cs:行373在c:Codektfs1ProjectsCRMDEVRenewalRenewalUnitTestsBridgestoneTests.cs:line 190

我最终将税收计算移到其他地方并删除了机会产品上的插件。这使得锁定问题消失了。不幸的是,我不得不在几个地方复制代码,因为它被调用了多种方式。

你在你的插件中使用什么样的管道阶段?尝试将其更改为"Pre-operation"。(你在插件中更新了一些其他实体吗?)

或者(如果业务逻辑允许)将执行模式更改为"异步"。

最新更新