I have an SQL Agent Job on a production server that keeps failing with the below messages. It is supposed to be capturing SQL Server activity using the SP_WHOISACTIVE
stored proc, at regularly scheduled intervals.
Executed as user: Warning: Null value is eliminated by an aggregate
or other SET operation. [SQLSTATE 01003] (Message 8153)Warning: Null value is eliminated by an aggregate or other SET
operation. [SQLSTATE 01003] (Message 8153)Warning: Null value is eliminated by an aggregate or other SET
operation. [SQLSTATE 01003] (Message 8153)Violation of PRIMARY KEY constraint 'PK_WhoIsActive'. Cannot insert
duplicate key in object 'monitoring.WhoIsActive'. The duplicate key
value is (Jan 20 2017 8:25AM, 109). [SQLSTATE 23000] (Error 2627)The statement has been terminated. [SQLSTATE 01000] (Error 3621).
The step failed.
Any idea what may be causing this?
What steps should I follow to fix this error?
Best Answer
Automate capturing SQL Server activity with
SP_WHOISACTIVE
andSP_WHO2
via a SQL Agent jobObviously your current process has an issue trying to insert duplicate data on a table with a constraint that doesn't allow such data to be duplicated where the value is
Jan 20 2017 8:25AM, 109
per the definedPK_WhoIsActive
Primary Key.I've copied the logic I've used with success on this sort of task below. I run the create table logic once (for both) but save it to a commented out or skipped SQL Agent step for future reference only.
I shared both the
SP_WHOISACTIVE
and theSP_WHO2
capturing methods and logic below but be sure you're on the DB to run theSP_WHO2
processes as it's logic is implicit. Be sure to specify the table and DB Names in theSP_WHOISACTIVE
processes since its logic is explicit.SP_WhoIsActive Table Capturing
Create Table
Capture to Table
SP_WHO2 Table Capturing
Create Table
Capture to Table