Dynamics CRM 365 建立使用者的時候報:The specified Active Directory user already exists as a Dynamics 365 user
阿新 • • 發佈:2020-09-12
用程式碼建立CRM賬號,域使用者建立後,建立CRM賬號時某種原因報錯,再次建立相同賬號的時候,就會報錯:The specified Active Directory user already exists as a Dynamics 365 user
日誌下載下來之後,詳細資訊顯示如下:The specified Active Directory user already exists as a Dynamics 365 user
但檢查了systemuser這張表發現確實是沒有這個使用者的,那為什麼還會有這個錯誤呢?
背景:想起來之前還原過一次DB,只還原了業務庫,沒有還原MSCRM_Config這個庫
原因:這個使用者之前由於某種原因在環境2中建立了一次,但沒有在環境1中建立,後來還原環境1的Org_MSCRM的資料庫到環境2,導致環境2中的這個使用者資訊被刪除掉了,
但是:使用者的資訊建立後不僅僅只存在systemuser這張表中,還會在MSCRM_Config的一些表中儲存相關資訊,所以當再次在環境2建立該使用者時,就會提示已經存在,不允許在建立了。
解決辦法:刪除掉MSCRM_Config庫中跟這個使用者相關的一些資訊,主要存在SystemUserOrganizations和SystemUserAuthentication這兩個表中,具體SQL語句如下
- 查詢系統中已經不存在的使用者在SystemUserOrganizations中的資訊
select * from SystemUserOrganizations where organizationid='29CA5B3F-8FD1-E611-93FB-00155DC81318' and crmuserid not in ( select systemuserid from [Org_MSCRM].dbo.systemuserbase)
- 查詢系統中已經不存在的使用者在SystemUserAuthentication中的資訊
select * from SystemUserAuthentication where userid in ( select userid from SystemUserOrganizations where organizationid='29CA5B3F-8FD1-E611-93FB-00155DC81318' and crmuserid not in ( select systemuserid from [Org_MSCRM].dbo.systemuserbase) )
- 刪除系統中已經不存在的使用者在SystemUserOrganizations中的資訊
delete from SystemUserOrganizations where organizationid='29CA5B3F-8FD1-E611-93FB-00155DC81318' and crmuserid not in ( select systemuserid from [Org_MSCRM].dbo.systemuserbase)
- 刪除系統中已經不存在的使用者在SystemUserAuthentication中的資訊
delete from SystemUserAuthentication where userid in ( select userid from SystemUserOrganizations where organizationid='29CA5B3F-8FD1-E611-93FB-00155DC81318' and crmuserid not in ( select systemuserid from [Org_MSCRM].dbo.systemuserbase) )
備註:DB中刪除完之後,需要等待一會才可以正常建立,等個5-10分鐘吧