Tuesday 30 December 2008

Error ''Item has already been added'' when trying to set Resource Type in a CMDB or Connector Rule

Applies To

• Altiris Connector 6.5
• CMDB 6.5


Problem/Symptoms

After upgrading to CMDB/Asset 6.5, when trying to set the Resource Type within a CMDB or Connector rule, the following error may be shown:

Module: AltirisNativeHelper.dll
Source: global.asax
Description: Unhandled exception.  Type=System.ArgumentException Msg=Item has already been added.  Key in dictionary: "8b92ef99-7bac-49a0-8694-48d7558bc7ee"  Key being added: "8b92ef99-7bac-49a0-8694-48d7558bc7ee"
StackTrace=
   at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
   at System.Collections.Hashtable.Add(Object key, Object value)
   at Altiris.NS.Connector.Web.ImportExportRule.CreateDataClassesMappingsTable(Boolean bReloadColumns, Boolean bSetSavedValues)
   at Altiris.NS.Connector.Web.ImportExportRule.CreateAllMappingControls(Boolean bReloadColumns, Boolean bSetSavedValues)
   at Altiris.NS.Connector.Web.ImportExportRule.ResourceType_Change(Object sender, EventArgs e)
   at System.Web.UI.WebControls.ListControl.OnSelectedIndexChanged(EventArgs e)
   at System.Web.UI.WebControls.DropDownList.System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent()
   at System.Web.UI.Page.RaiseChangedEvents()
   at System.Web.UI.Page.ProcessRequestMain()

The following Resource Types have been reported as affected by this issue, others could be affected:

Computer
Monitor
Network Printer
Office Equipment
Peripheral
Scanner


Cause

This can be caused by having the Accounting Information data class directly associated to a child Resource Type and the child's Base Resource Type, Asset.


Resolution

  1. Back up the Altiris database
  2. Run the following sql script against the Altiris database


--Set up @ResourceTypeDataClassAssoc table variable
DECLARE @ResourceTypeDataClassAssoc TABLE
(
ResourceType nvarchar(250),
ResourceTypeGuid uniqueidentifier,
depth bit,
BaseResourceType nvarchar(250),
BaseResourceTypeGuid uniqueidentifier,
DataClass nvarchar(250),
ResourceDataClassGuid uniqueidentifier
)

/*
populate @ResourceTypeDataClassAssoc with data classes
associated to resource types at each level in the hierarchy
*/
INSERT INTO @ResourceTypeDataClassAssoc
SELECT i.name as ResourceType, rth.ResourceTypeGuid, rth.depth, i2.name as BaseResourceType,
rth.BaseResourceTypeGuid, i3.name as DataClass, rtdc.ResourceDataClassGuid
FROM ResourceTypeHierarchy rth
JOIN item i on rth.ResourceTypeGuid = i.Guid
JOIN item i2 on rth.BaseResourceTypeGuid = i2.Guid
JOIN ResourceTypeDataClass rtdc on rth.BaseResourceTypeGuid = rtdc.ResourceTypeGuid
JOIN item i3 ON rtdc.ResourceDataClassGuid = i3.Guid

/*
Find resource types that have data classes associated directly, and indirectly through
any base resource type in their hierarchy, and delete them from the ResourceTypeDataClass table
*/
DELETE FROM ResourceTypeDataClass
WHERE EXISTS
(
SELECT *
FROM @ResourceTypeDataClassAssoc rt1
  JOIN @ResourceTypeDataClassAssoc rt2 ON rt1.ResourceTypeGuid = rt2.ResourceTypeGuid
  AND rt1.BaseResourceType != rt2.BaseResourceType
  AND rt1.ResourceDataClassGuid = rt2.ResourceDataClassGuid
WHERE rt1.depth = 0
  AND ResourceTypeDataClass.ResourceTypeGuid = rt1.ResourceTypeGuid
  AND ResourceTypeDataClass.ResourceDataClassGuid = rt1.ResourceDataClassGuid
)

No comments:

Post a Comment