Enable change tracking (CDC) on a MSSQL database when getting Msg 22830

Recently we received a request to enable change tracking on a database but kept getting an error even under a user with the SA role.

Msg 22830, Level 16, State 1, Procedure sp_cdc_enable_db_internal, Line 195
Could not update the metadata that indicates database DBNAME┬áis enabled for Change Data Capture. The failure occurred when executing the command ‘SetCDCTracked(Value = 1)’. The error returned was 15517: ‘Cannot execute as the database principal because the principal “dbo” does not exist, this type of principal cannot be impersonated, or you do not have permission.’. Use the action and error to determine the cause of the failure and resubmit the request.

The reason for this error is because you don’t have a valid login for the database. This is probably happening, because like me, you restored the DB to another server. So just run the command below to switch the owner and enable CDC. Make sure to change DBNAME to the name of your database.

USE DBNAME
GO
sp_changedbowner ‘sa’
GO

USE DBNAME
GO
EXEC sys.sp_cdc_enable_db
GO

Leave a Comment

Your email address will not be published.