【问题标题】:CRM Cannot obtain lock on resource when adding OpportunityProduct添加 OpportunityProduct 时 CRM 无法获取资源锁定
【发布时间】:2014-08-04 19:31:28
【问题描述】:

我在 OpportunityProduct 上有一个插件,可以在创建或更新商品时计算商品的税金。大多数时候它工作正常,但是当我以编程方式添加许多产品时,它有时会失败,但以下例外。

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

这是带有汇总 15(v2) 的 CRM 2011 的本地安装。

有什么想法吗?

谢谢, 比尔

Microsoft.Xrm.Sdk.SaveChangesException:处理此请求时发生错误。 ---> System.ServiceModel.FaultException1[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 动作) 在 Microsoft.Xrm.Client.Services.OrganizationService.Execute(组织请求请求) 在 Microsoft.Xrm.Client.Services.CachedOrganizationService.InnerExecute(组织请求请求) 在 Microsoft.Xrm.Client.Services.OrganizationServiceCache.InnerExecute[TRequest,TResponse,TResult](TRequest 查询,Func2 execute, Func2 选择器) 在 Microsoft.Xrm.Client.Services.OrganizationServiceCache.InnerExecute[TRequest,TResponse,TResult](TRequest 请求,Func2 execute, Func2 选择器,字符串 selectorCacheKey) 在 Microsoft.Xrm.Client.Services.OrganizationServiceCache.Execute[T](OrganizationRequest 请求,Func2 execute, Func2 选择器,字符串 selectorCacheKey) 在 Microsoft.Xrm.Client.Services.CachedOrganizationService.Execute[T](OrganizationRequest 请求,Func5 execute, Func2 选择器,字符串 selectorCacheKey) 在 Microsoft.Xrm.Client.Services.CachedOrganizationService.Execute[T](OrganizationRequest 请求,Func2 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, IList1 结果) --- 内部异常堆栈跟踪结束 --- 在 Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges(SaveChangesOptions 选项) 在 Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges() 在 RenewalUnitTests.CrmTest.CreateProposalServiceCode(Guid proposalId,字符串 serviceCodeNumber,字符串 servicePeriodNumber,字符串 servicePeriodNumber2,Int32 数量,字符串 uomName)在 c:\Code\ktfs1\Projects\CRM\DEV\Renewal\RenewalUnitTests\CrmTest.cs:line 373 在 c:\Code\ktfs1\Projects\CRM\DEV\Renewal\RenewalUnitTests\BridgestoneTests.cs:line 190 中的 BridgestoneUnitTests.BridgestoneTests.EmailSimpleProposal() 处

【问题讨论】:

    标签: dynamics-crm-2011


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      您在插件中使用了哪种管道阶段?尝试将其更改为“预操作”。 (您是否更新了该插件中的其他一些实体?)

      或者(如果可能通过业务逻辑)将执行模式更改为“异步”。

      【讨论】:

      • 运行在预运行阶段。抱歉,我没有指定这一点。我最初在手术后使用它,但遇到了更多的锁定问题。异步不是一个选项。表单刷新时必须显示税款。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多