错误信息
Generic SQL error.
Server stack trace:
在 System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
在 System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
在 System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
在 System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
Exception rethrown at [0]:
在 Microsoft.Xrm.Tooling.Connector.CrmServiceClient.RetrieveMultiple(QueryBase query)
如果增删改正常,在查询的时候报这个错误,那很可能是由于组织服务最终转化的SQL查询时间超时。
例如
QueryExpression gQuery = new QueryExpression("new_log")
{
Distinct = false,
NoLock = true,
ColumnSet = new ColumnSet(new string[] { "new_content" }),
Criteria = new FilterExpression()
};
Query.Criteria.AddCondition("new_content", ConditionOperator.Contains, key);
Query.Criteria.AddCondition("statecode", ConditionOperator.Equal, 0);
EntityCollection entityCollection = service.RetrieveMultiple(Query);
上面这个组织服务的查询中,使用了Contains,也就是SQL中的LIKE “%%”。这种查询非常消耗时间,当数据量太大了,就容易超时,报这个错误。
解决办法
1、优化查询
//Query.Criteria.AddCondition("new_content", ConditionOperator.Contains, key);
当注释这行代码的时候,就能正常执行,查询出来结果。
2、修改超时时间限制
在CRM 服务器注册表里 添加如下键
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSCRM\OLEDBTimeout 600