No Classic Robots Showing In Orchestrator - Error resolution for " Cannot Insert Duplicate Key In Object 'dbo.@temp'. The Duplicate Key Value Is ({MachineName})" .
Issue Description:
- After restarting Orchestrator for a maintenance window, classic Robots would not connect and none were listed in the Tenant Robots page. A generic "An error has occurred" error is thrown.
- When attempting to connect a classic Robot to Orchestrator, a similar error, "An error has occurred" is thrown.
Orchestrator Event Viewer log error indicates:
System.Data.SqlClient.SqlException (0x80131904): Violation of PRIMARY KEY constraint 'PK__#AF6C401__C41E02883FBC4D4E'. Cannot insert duplicate key in object 'dbo.@temp'. The duplicate key value is ({MachineName}). The statement has been terminated. at Task<DbDataReader> System.Data.SqlClient.SqlCommand.ExecuteDbDataReaderAsync
The dbo.@temp refers to a table variable that should be deleted upon the termination of the session, but in this scenario is persistent. The {MachineName} is the machine used to run a standard robot. As the Robots page will not populate, the relevant machine key can be obtained from the Robot Orchestrator connections settings, if needed.
The Robot Event Viewer log will include an error of:
RemoteException wrapping UiPath.Service.Orchestrator.Clients.OrchestratorHttpException: An error has occurred. at UiPath.Service.Orchestrator.OrchestratorClientExtensions.<EnsureOrchestratorStatusCodeAsync>d__3.MoveNext()
Resolution: Identified the issue as a duplicate robot license assignment that caused a database collision; set the duplicate license key to null for resolution.
- Stop the Orchestrator server.
- Access the Orchestrator database and run the following query against the dbo.RobotLicenses table:
-
SELECT * WHERE LicenseKey = {MachineKey of affected robot}
-
- Identify the duplicate RobotId entries and determine the Id to be nullified, as setting Enabled=0 does not resolve the issue.
- The RobotId will correspond to an Id in the Robots table, which should include the corresponding LicenseKey.
- Run the following query against the dbo.RobotLicenses table:
-
UPDATE RobotLicenses
SET LicenseKey = <NULL>
WHERE Id = {TargetId}
-
- Restart Orchestrator and confirm the Robots populate and can connect as expected.