0x80040237 无法插入重复键。
我正在尝试通过 CrmService 为 MSCRM4.0 编写导入例程。
到目前为止,这已经是成功的。 最初我只是让 CRM 生成记录的主键。 但我的客户希望能够将自定义实体的键设置为预定义值。 这可能使我们能够知道安装程序创建了哪些数据以及安装后创建了哪些数据。
我进行了测试,以确保在调用 CrmService.Update() 方法时可以设置 Guid,结果表明记录是使用我们所需的值创建的。 我运行了导入,一切似乎都很成功。 在修改导入文件的验证代码时,我删除了数据(通过 crm 浏览器界面)并尝试重新导入。 不幸的是,现在它抛出了重复的键错误。
为什么会抛出这个错误? Crm界面是否删除了该记录,或者该记录仍然存在但隐藏在用户的视线之外? 有没有办法确保删除的记录被永久删除并且Guid变得免费? 在实际环境中,这些指南永远不会存在,但在我的开发过程中,我需要这些导入才能成功。
顺便说一句,考虑到我遇到了这个问题,这是否意味着静态设置 Guid 不是推荐的做法?
0x80040237 Cannot insert duplicate key.
I'm trying to write an import routine for MSCRM4.0 through the CrmService.
This has been successful up until this point. Initially I was just letting CRM generate the primary keys of the records. But my client wanted the ability to set the key of a our custom entity to predefined values. Potentially this enables us to know what data was created by our installer, and what data was created post-install.
I tested to ensure that the Guids can be set when calling the CrmService.Update() method and the results indicated that records were created with our desired values. I ran my import and everything seemed successful. In modifying my validation code of the import files, I deleted the data (through the crm browser interface) and tried to re-import. Unfortunately now it throws and a duplicate key error.
Why is this error being thrown? Does the Crm interface delete the record, or does it still exist but hidden from user's eyes? Is there a way to ensure that a deleted record is permanently deleted and the Guid becomes free? In a live environment, these Guids would never have existed, but during my development I need these imports to be successful.
By the way, considering I'm having this issue, does this imply that statically setting Guids is not a recommended practice?
发布评论
评论(3)
据我所知,实体是软删除的,因此除非您(或删除服务)将实体从数据库中删除,否则无法重用该 Guid。
例如,在 LeadBase 表中,您会发现一个名为 DeletionStateCode 的字段,值为 0 表示该记录尚未删除。
值 2 标记要删除的记录。 有一个删除服务每 2(?) 小时运行一次,以从表中物理删除这些记录。
As far I can tell entities are soft-deleted so it would not be possible to reuse that Guid unless you (or the deletion service) deleted the entity out of the database.
For example in the LeadBase table you will find a field called DeletionStateCode, a value of 0 implies the record has not been deleted.
A value of 2 marks the record for deletion. There's a deletion service that runs every 2(?) hours to physically delete those records from the table.
我认为 Zahir 是对的,尝试运行删除服务并重试。 这里有一些信息: http://blogs.msdn.com/crm/archive/2006/10/24/purging-old-instances-of-workflow-in-microsoft-crm.aspx
I think Zahir is right, try running the deletion service and try again. There's some info here: http://blogs.msdn.com/crm/archive/2006/10/24/purging-old-instances-of-workflow-in-microsoft-crm.aspx
查希尔是对的。
导入并删除记录后,您可以在选择的时间启动删除服务 此工具。 这将使测试导入和重新导入变得更加容易。
Zahir is correct.
After you import and delete the records, you can kick off the deletion service at a time you choose with this tool. That will make it easier to test imports and reimports.