Commit 6e83e26
Rework CDC exclusion: program_name->job_id via msdb, text fallback (#1096)
Replace the text-only CDC filter with a precise, two-tier signal:
1. Primary: resolve capture job_id(s) from msdb.dbo.cdc_jobs (job_type =
'capture') and match the running session by decoding its SQL Agent
program_name ('SQLAgent - TSQL JobStep (Job 0x<job_id> : Step N)').
The decode -- CONVERT(uniqueidentifier, CONVERT(binary(16),
SUBSTRING(program_name, 32, 32), 2)) -- was validated by round-tripping
real msdb.dbo.sysjobs rows. This is CDC-specific and never hides other
Agent jobs.
2. Fallback: when the account can't read msdb.dbo.cdc_jobs (or the table
doesn't exist -- it is created lazily on first CDC config), match the
whole batch/object text (sp_MScdc_capture_job / sp_cdc_scan).
The msdb reference is deferred through sp_executesql inside TRY/CATCH so an
inaccessible msdb raises a *catchable* error (not an uncatchable cross-db
916) and the query degrades to the text path instead of failing. Verified
against SQL 2016: with cdc_jobs absent, the TRY/CATCH sets @cdc_readable=0,
the batch completes, and the text fallback engages.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent dc0a945 commit 6e83e26
1 file changed
Lines changed: 36 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
766 | 766 | | |
767 | 767 | | |
768 | 768 | | |
769 | | - | |
770 | | - | |
771 | | - | |
772 | | - | |
773 | | - | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
774 | 804 | | |
775 | 805 | | |
776 | | - | |
| 806 | + | |
777 | 807 | | |
778 | 808 | | |
779 | 809 | | |
| |||
0 commit comments