写入 CRM Online 时出现 SQL 错误

Getting an SQL error when writing to CRM Online

我正在寻找调试在尝试将记录写入 CRM Online 时遇到的错误的方法:

An unhandled exception of type 'System.ServiceModel.FaultException`1' occurred in Microsoft.Xrm.Sdk.dll

Additional information: Generic SQL error.

我正在从一个 CRM 实例读取数据,剥离值并使用 upsertrequest 写入另一个 CRM 实例。两个 CRM 实例安装了相同的 solution,因此定制应该相同。

我要删除的系统字段包括有关所有权、创建时间、修改时间等的信息。

因为是CRM Online,不知道怎么判断是什么错误。对于本地实例,您可以通过 SQL 分析或检查 CRM 跟踪日志来解决这个问题,但这两个选项都不适用于 CRM Online。

有人有什么建议吗?

// read the record from the Source environment
// columnSet_contact is a sub-set of columns excluding ownership details
var sourceContact = source.OrganizationServiceProxy.Retrieve
(
    "contact", 
    contactid, 
    columnSet_contact
);

// Contact requires TransactionCurrencyID
sourceContact.Attributes["transactioncurrencyid"] = new EntityReference
(
    "transactioncurrency", 
    targetEnvCurrencyId       // id of Currency in target env retrieved previously
);

// write to target environment
target.OrganizationServiceProxy.Execute
(
    new XrmMessages.UpsertRequest 
    { 
        Target = sourceContact 
    }
);

遗憾的是,如果不联系 MS 支持,就无法从在线组织中获取更多信息。

如果您使用 Create/Update 而不是 Upsert,是否会遇到同样的问题?当目标环境与源环境相同时怎么办?

我也会尝试修改您的逻辑,以便排除名称以外的所有内容。该问题可能会消失...如果确实存在,请逐个添加属性,直到找到导致问题的那个。