CRM添加OpportunityProduct时无法获取资源锁定

时间:2014-08-04 19:31:28

标签: dynamics-crm-2011

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

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

这是CRM 2011的内部部署安装,汇总15(v2)。

有什么想法吗?

谢谢, 比尔

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动作)    在Microsoft.Xrm.Client.Services.OrganizationService.Execute(OrganizationRequest request)    在Microsoft.Xrm.Client.Services.CachedOrganizationService.InnerExecute(OrganizationRequest request)    在Microsoft.Xrm.Client.Services.OrganizationServiceCache.InnerExecute [TRequest,TResponse,TResult](TRequest查询,Func 2 execute, Func 2选择器)    在Microsoft.Xrm.Client.Services.OrganizationServiceCache.InnerExecute [TRequest,TResponse,TResult](TRequest请求,Func 2 execute, Func 2选择器,字符串selectorCacheKey)    在Microsoft.Xrm.Client.Services.OrganizationServiceCache.Execute [T](OrganizationRequest请求,Func 2 execute, Func 2选择器,字符串selectorCacheKey)    在Microsoft.Xrm.Client.Services.CachedOrganizationService.Execute [T](OrganizationRequest请求,Func 5 execute, Func 2选择器,字符串selectorCacheKey)    在Microsoft.Xrm.Client.Services.CachedOrganizationService.Execute [T](OrganizationRequest请求,Func 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()    at RenewalUnitTests.CrmTest.CreateProposalServiceCode(Guid proposalId,String serviceCodeNumber,String servicePeriodNumber,String servicePeriodNumber2,Int32 quantity,String uomName)在c:\ Code \ ktfs1 \ Projects \ CRM \ DEV \ Renewal \ RenewalUnitTests \ CrmTest.cs:第373行    在BridgestoneUnitTests.BridgestoneTests.EmailSimpleProposal()在c:\ Code \ ktfs1 \ Projects \ CRM \ DEV \ Renewal \ RenewalUnitTests \ BridgestoneTests.cs:第190行

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

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