marcingminski / sqlwatch

SQL Server Performance Monitor
https://docs.sqlwatch.io
Other
436 stars 173 forks source link

Cannot insert duplicate key row in object 'dbo.sqlwatch_meta_procedure' with unique index 'idx_sqlwatch_meta_procedure_1'. #391

Open sozezzo opened 3 years ago

sozezzo commented 3 years ago

Describe the bug We use a Central Repository for many SqlWatch databases.

There is job 'SQLWATCH-[dbaWatch]-INTERNAL-CONFIG' that fail on step 9 'dbo.usp_sqlwatch_internal_add_procedure'

Date        2021-06-11 11:00:27 AM
Log     Job History (SQLWATCH-[dbaWatch]-INTERNAL-CONFIG)

Step ID     9
Server      SQL-DB3
Job Name        SQLWATCH-[dbaWatch]-INTERNAL-CONFIG
Step Name       dbo.usp_sqlwatch_internal_add_procedure
Duration        00:00:00
Sql Severity    14
Sql Message ID  2601
Operator Emailed    
Operator Net sent   
Operator Paged  
Retries Attempted   0

Message
Executed as user: Contoso\UserSqlWatch. Cannot insert duplicate key row in object 'dbo.sqlwatch_meta_procedure' 
with unique index 'idx_sqlwatch_meta_procedure_1'. 
The duplicate key value is (SQL-DB3, 1, Ad-Hoc Query 3FBE6AA6). [SQLSTATE 23000] (Error 2601).  The step failed.`

To Reproduce There are the same databases on many different servers and use a Central Repository. The error only happens in the Central repository.

FIX image

WHERE sql_instance = @sql_instance -- fix error : Cannot insert duplicate key row in object 'dbo.sqlwatch_meta_procedure' with unique index 'idx_sqlwatch_meta_procedure_1'.