Working with a client in our Multi-tenant CRM environment who was doing a database migration into CRM and as part of the process, a backup of their Organization_MSCRM database was taken just prior to starting the migration in case it needed to be restored and run a second time.
In this case it did, so I restored the database and let the client know he should be good to go. A few hours later I received a call that they were unable to add some new users, they would appear as available when using the add multiple user wizard, but anyone added would not be added to CRM. It was also disucussed that these users had been added to CRM initally AFTER the database backup had been taken.
I turned on tracing and tried to add the users through both the single user form and multiple user interface and was unable to do so. The error message in the logs wasn't much help:
Unexpected error adding user
[email protected]: Microsoft.Crm.CrmException: INVALID_WRPC_TOKEN: Validate WRPC Token: WRPCTokenState=Invalid, TOKEN_EXPIRY=4320, IGNORE_TOKEN=False
Searching on Google or bing didn't offer any assitance. Apparently not a very common problem, or no one has been able to resolve.
I did some searching in the MSCRM_CONFIG database and found that their are several user tables there and after getting my head around the structure found that there were enties here for users that were not part of the restored DB. It seems that new users are added to both the Orgnaization_MSCRM and MSCRM_CONFIG and after the
restore these were out of sync.
I needed to remove the extra entries in order to address. Restoring the MSCRM_CONFIG database was not an option as other clients could have been adding users at this point and to
restore would risk breaking their instances of CRM.
Long story short, I was finally able to generate a script to remove the bad entries and when I tried to add users again, I was succesful. In case someone else out there finds themselves in a similar situation, here is the script I used to delete the bad entries.
DECLARE @UsersToDelete TABLE
(
UserId uniqueidentifier
)
Insert Into @UsersToDelete(UserId)
Select UserId from [MSCRM_CONFIG].[dbo].[SystemUserOrganizations]
Where CrmuserId Not in (select systemuserid from Organization_MSCRM.dbo.SystemUserBase)
And OrganizationId = '00000000-643F-E011-0000-0050568572A1' --Id From the Organization table for this instance
Delete From [MSCRM_CONFIG].[dbo].[SystemUserAuthentication]
Where UserId in (Select UserId From @UsersToDelete)
Delete From [MSCRM_CONFIG].[dbo].[SystemUserOrganizations]
Where UserId in (Select UserId From @UsersToDelete)
Delete From [MSCRM_CONFIG].[dbo].[SystemUser]
Where Id in (Select UserId From @UsersToDelete)