Received the error: "Violation of PRIMARY KEY constraint 'PK_TaskTargetDeviceCache_Guid'. Cannot insert duplicate key in object 'dbo.TaskTargetDeviceCache'." when attempting to manage Task Servers
search cancel

Received the error: "Violation of PRIMARY KEY constraint 'PK_TaskTargetDeviceCache_Guid'. Cannot insert duplicate key in object 'dbo.TaskTargetDeviceCache'." when attempting to manage Task Servers

book

Article ID: 176949

calendar_today

Updated On:

Products

IT Management Suite Task Server

Issue/Introduction

When attempting to task servers, the following page is displayed instead of the task server's page:

Server Error in '/Altiris/NS' Application.
--------------------------------------------------------------------------------

Violation of PRIMARY KEY constraint 'PK_TaskTargetDeviceCache_Guid'. Cannot insert duplicate key in object 'dbo.TaskTargetDeviceCache'.
The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: Violation of PRIMARY KEY constraint 'PK_TaskTargetDeviceCache_Guid'. Cannot insert duplicate key in object 'dbo.TaskTargetDeviceCache'.
The statement has been terminated.

 

Cause

Duplicate GUIDS.  A computer appeared in multiple partitioned tables where it should have only been listed in one. 

Diagnosis:

  1. Ran Profiler and determined the SP running was tmBuildTargetDeviceCache.  Running this manually in SQL gives essentially the same error, that a duplicate key could not be inserted into the table.
  2. Looked at the target table - TaskTargetDeviceCache. It was discovered that 1) that it was empty, and 2) that it had the primary key as the main GUID file.  There are two places for GUID's, but the key is only the first one.
  3. Checked the code behind the Stored Procedure that is pulling GUIDs from the vTaskTargetDevices table.
  4. There is a possibility that a computer record exists in multiple tables
  5. A Query can be ran to see if you have a "Duplicate" GUID issue (where a computer shows up in multiple partitioned tables):

    select *
    from vResourceEx vr
    where exists
    (
     select [Guid], count(*)
     from [dbo].[vTaskTargetDevices] vt
     where vr.guid=vt.guid
     group by guid
     having count(*)>1
    )

  6. This query will return computer guids, typeguids & Names. If you have a "duplicate" GUID issue, you will see the same computer listed twice. Programatically, we should be preventing there ever being a record in more than one table.  In NS6 we did this by having a single container for all records: the Item table.  In NS7 we should be doing this programatically.

We think what one scenario that may cause this is having a Virtual Machine that is converted to a Physical one (or vice-versa), and that this is something we did not test prior to our release. We still do not know for certain that this is what happend, but we have confirmed with some of our customers who have seen this issue that they do VM conversions on occasion. The root-cause is as yet unknown.

Resolution

Once you have identified the computers that show up in multiple tables (using the SQL query listed above), try deleting them through the NS console (if possible) and letting the record regenerate.

If the computers do not show up in the NS console (or if removing them & Re-adding them does not work), Contact Altiris support.

Notes for Support: Adjust the attribute for the "duplicate" computers to "Deleted" by updating the appropriate table. For example, if the machines that show up as duplicate are Virtual machines you would want to set the deleted attribute on the Physical partition table.


Applies To
NS 7.0 & SMS or CMS 7.0