1

I'm currently synchronizing data between Maria <--> MSSQL. That is 2 way sync. I used SQL Server on Windows and everything works well until several days before... I switched all the test DB to Linux server, so MSSQL was run on a Docker container (the official image).

My Env

  • MSSQL Docker image
  • Ubuntu (MacOS also), the CPU and RAM requirement was ensured both for device and Docker.

My problem:

The SQL Agent Job ran perfectly for ~10 minutes. After that, no changes were captured into cdc.dbo_MyTrackedTable_CT.

I want this CDC job will run forever.

I got this message:

Executed as user: 1b23b4b8a3ec\1b23b4b8a3ec$. 
Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32). [SQLSTATE 42000] (Error 217)

My inspection

EXEC msdb.dbo.sp_help_job
    @job_name = N'cdc.MyDBName_capture',
    @job_aspect = N'ALL' ;

Return: last_outcome_message

The job failed. The Job was invoked by User sa. The last step to run was step 2 (Change Data Capture Collection Agent).

.

Next, take a further inspection:

SELECT 
 job.*, '|'  as "1"
 , activity.*, '|' as "2", history.*
 , CASE
        WHEN history.[run_status] = 0 THEN 'Failed'
        WHEN history.[run_status] = 1 THEN 'Succeeded'
        WHEN history.[run_status] = 2 THEN 'Retry (step only)'
        WHEN history.[run_status] = 3 THEN 'Canceled'
        WHEN history.[run_status] = 4 THEN 'In-progress message'
        WHEN history.[run_status] = 5 THEN 'Unknown'
        ELSE 'N/A' END as Run_Status
 FROM msdb.dbo.sysjobs_view job
 INNER JOIN msdb.dbo.sysjobactivity activity ON job.job_id = activity.job_id
 INNER JOIN msdb.dbo.sysjobhistory history ON job.job_id = history.job_id
 WHERE 1=1
    AND job.name = 'cdc.MyDBName_capture'
    AND history.run_date = '20180122'

Return: See this SQL result Image

Sorry I don't have enough repu to embed img, so the link instead.

As you can see the CDC job will start and run..and..retry for 10 times, after 10times, I cannot capture changes anymore.

I need to start the job again by:

EXEC msdb.dbo.sp_start_job N'cdc.MyDbName_capture';

Then foreach ~1 minutes, the job retry --> till 10 --> job was stopped ¯_(ツ)_/¯


So can you tell me why and how to fix it ??

FYI, This is my job configuration:

-- https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sys-sp-cdc-add-job-transact-sql

EXECUTE sys.sp_cdc_change_job
   @job_type = N'capture',
   @maxscans = 1,
   @maxtrans = 500,
   @continuous = true,
   @pollinginterval = 1
;

It's also not a trigger issue right? I feel dangerous when trying to turn trigger off, but no luck was made.

-- Turn off recursion trigger
ALTER DATABASE MyDBName
SET RECURSIVE_TRIGGERS OFF;
Neo.Mxn0
  • 953
  • 2
  • 8
  • 25
  • This issue doesn't exist on Windows env. I still don't know why! But for anyone who struggles with this issue, plz come to MSSQL on Windows. – Neo.Mxn0 Jan 27 '18 at 12:29
  • Please, did you find any solution for this? – lcnicolau Mar 15 '21 at 21:16
  • @icnicolau I switched from MSSQL on Linux to an installed MSSQL server version on Windows. Sometimes, logical thinking is the weakness ^^ – Neo.Mxn0 Mar 16 '21 at 08:36
  • I found [the solution](https://stackoverflow.com/a/67347951/4071001), it is a bug in SQL Server 2017. It has nothing to do with the operating system, in fact I'm working on Windows from the beginning. – lcnicolau May 01 '21 at 15:48

2 Answers2

0

I am experiencing the same thing on SQL server 2017 running under windows server. Interestingly the same system has been running for no problems for years under SQL2012 so I am thinking it may be some bug introduced along the way.

I found with some retries the problem cleared so as a workaround I edited the job and increased the number of retries and haven't seen it again yet.

Tailslide
  • 71
  • 7
  • Hi Tailslide! This is probably better suited as a comment, rather than an answer. That way, people won't downvote it. Whenever you gain some reputation, try moving it to a comment. Then it'll protect your reputation points. – Clomp Mar 03 '18 at 00:24
  • Thanks I have been on here like 10 years and don't have enough points to participate in anything anyways so I don't really care about them.. I did stumble upon a workaround that worked for me so I updated my answer. – Tailslide Mar 10 '18 at 05:31
0

See KB4073684 - FIX: Change data capture does not work in SQL Server 2017.

This happens due to a declared bug:

Microsoft has confirmed that this is a problem in the Microsoft products...

Fix is included in Cumulative Update 4 for SQL Server 2017. However, they recommend simply installing the latest cumulative version:

Each new build for SQL Server 2017 contains all the hotfixes and security fixes that were in the previous build. We recommend that you install the latest build for SQL Server 2017.

lcnicolau
  • 3,252
  • 4
  • 36
  • 53