Network Management
Violation of PRIMARY KEY constraint error in NCM 2023.4 when performing an inventory job
When performing an "Update Inventory" job an error occurs regarding a violation of a primary key constraint. Cannot insert duplicate key in object.
First published date
Last published date
Overview
====================================================
<timestamp> : Started Update inventory on demand - <timestamp>
ERROR: Run job error: Violation of PRIMARY KEY constraint 'PK_NCM_RouteTable'. Cannot insert duplicate key in object 'dbo.NCM_RouteTable'. The duplicate key value is (56476a64-cdb3-4ec8-a499-01084364b4d7, X.X.X.X, Local, X.X.X.X).
The statement has been terminated.
___________________________________________________________________________
<timestamp> : Completed Update inventory on demand - <timestamp>
Execution time : <execution duration>
___________________________________________________________________________
=====================================================
In the example above, the problem table would be PK_NCM_RouteTable. Similar errors may occur for multiple NCM tables in the database.
Product section
Cause
Resolution
To resolve this problem, please upgrade to SolarWinds Platform 2024.1.1 and above. If upgrade is not possible, please perform the followings steps, ensure to backup the database using the following article:
- Connect to the Primary Polling Engine.
- Open Database Manager from the SolarWinds Platform folder of the Start Menu.
- Select Add Orion Server, then expand the SQL server and SolarWinds database in bold.
- Right-click the database and select New Query.
- Paste the following query, update it to point to the table shown in the error, and execute the query:
-- Scripts are not supported under any SolarWinds support program or service. -- Scripts are provided AS IS without warranty of any kind. SolarWinds further -- disclaims all warranties including, without limitation, any implied warranties -- of merchantability or of fitness for a particular purpose. The risk arising -- out of the use or performance of the scripts and documentation stays with you. -- In no event shall SolarWinds or anyone else involved in the creation, -- production, or delivery of the scripts be liable for any damages whatsoever -- (including, without limitation, damages for loss of business profits, business -- interruption, loss of business information, or other pecuniary loss) arising -- out of the use of or inability to use the scripts or documentation. ALTER TABLE <Table_in_Error> DROP CONSTRAINT <PK_in_Error> TRUNCATE TABLE <Table_in_Error>
- Run the Update Inventory Job afterwards.
- Only run the query on the table with the error from the Update Inventory Job log. (Another table may error out on the next job run).
- This does not guarantee a fix. If the Configuration Wizard is run after, the PK may return; if so, that particular MIB associated with the table may need to be unchecked from the Update Inventory job temporarily until a permanent fix is released.