21854 Error

zhang jay 1 Reputation point
2020-10-15T09:06:06.183+00:00

OS: Windows server 2008 R2
SQL: Windows server 2008 R2

I deleted all publications from this server, and then I try to create a publication, get a error message as below:
Error: 21854, Severity: 10, Could not add new article to publication ‘%s’ because of active schema change activities or a snapshot is being generated.

How can I resolve it?

Best Wishes,

SQL Server | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 121.4K Reputation points MVP Volunteer Moderator
    2020-10-15T21:48:09.163+00:00

    I have a copy of the resource database, so that I can search also code for system procedure. I found that this error is raised in sp_addarticle:

            -- Get applock to co-ordinate with snapshot agent. Basically,  
            -- we want to prevent a new article from being added while a   
            -- snapshot is being generated.  
            EXEC @applock_result = sys.sp_getapplock @Resource = @publication,  
                    @LockMode = N'Exclusive',  
                    @LockOwner = N'Transaction',  
                    @LockTimeout = 0,  
                    @DbPrincipal = N'db_owner'  
      
            IF @applock_result < 0  
            BEGIN  
                RAISERROR(21854, 16, -1, @publication)  
                GOTO UNDO  
            END  
    

    It seems that there is another operation running on the publication which also has taken this application lock.

    I don't whereelse this application lock may be taken, but one possibility would be to set the database offline and then online again to roll back all open transaction.

    You could also look for processes with this application lock, but I'm not sure if it is worth the effort.

    0 comments No comments

  2. Cris Zhan-MSFT 6,661 Reputation points
    2020-10-16T02:07:48.35+00:00

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.