Hello.
I used CDC feature for a time to collect application data and send it to data warehouse and everything worked well. Then few weeks ago I noticed that my function that retrieves net changes (in my case [cdc].[fn_cdc_get_net_changes_dbo_info_rg_3830]) became to work very slow. I found article (https://support.microsoft.com/en-us/kb/2989478) about poor performance for cdc.fn_cdc_get_net_changes_<capture_instance> in SQL Server 2012 SP2 and since my SQL Server version was 11.0.5343.0 (2012 SP2) I decided to update Microsoft SQL Server 2012 to Service Pack 3 (version 11.0.6020.0).
So, after update I'm unable to use CDC at all. Each time I try to start capture job in Agent it fails and raises a bunch of errors first of those is 2601:
Entry Time 2016-03-10 11:58:44.173, Msg 2601, Level 14, State 1, Cannot insert duplicate key row in object "cdc.dbo_info_rg_3830_CT" with unique index "dbo_info_rg_3830_CT_clustered_idx". The duplicate key value is (0x00e6dd33000043080012, 0x00e6dd33000042d0000d, 1). For more information, query the sys.dm_cdc_errors dynamic management view.
Neither sys.dm_cdc_errors nor sys.dm_cdc_log_scan_sessions DMV provide any valuable information.
That clustered index on the changes table is defined as follows:
CREATE UNIQUE CLUSTERED INDEX [dbo_info_rg_3830_CT_clustered_idx] ON [cdc].[dbo_info_rg_3830_CT] ( [__$start_lsn] ASC, [__$seqval] ASC, [__$operation] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [com_cdc_fg] GO
Of course specific values of index columns that cause error every time are different. But I noticed that [__$operation] is always 1. So duplicates are always about deleting rows.
I tried do disable/re-enable CDC on database and table, tried to enable different table in the same database, tried to backup/shrink transaction log and then re-enable CDC and result was always the same. The database I try to enable CDC for doesn't participate in mirroring, replication etc.
What is interesting is that I can enable CDC on different database on the same server instance and it works well, collects data and writes it to the changes tables just as it should. So the problem is relevant with that specific database.
Any ideas?