How to Fix SQL Server Error 21871 (Msg 21871)
You trigger sql server error 21871 when you query or validate a replication publisher before redirection. You fix it by registering the redirected publisher host name on the distributor server first. This failure returns message 21871 with severity level 16 from the database engine. The engine reports that the specified publisher of the target database has not been redirected. Teams see this message during replication setup or failover testing. What causes sql server error 21871 in replicatio
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You trigger sql server error 21871 when you query or validate a replication publisher before redirection. You fix it by registering the redirected publisher host name on the distributor server first.
This failure returns message 21871 with severity level 16 from the database engine. The engine reports that the specified publisher of the target database has not been redirected. Teams see this message during replication setup or failover testing.
What causes sql server error 21871 in replication
Replication uses a distributor server to track which node holds the active published database. When a primary node changes, the distributor needs a redirection record for the new host. If you check or remove redirection before that record exists, the engine throws message 21871.
Severity 16 means the error comes from a user request or missing setup step. The database engine itself is still healthy and running fine. The distributor catalog just lacks the mapping between the original publisher and the new target.
Engineers often hit this issue when scripts run out of order during a cluster failover. A script might try to validate redirection before the setup step finishes. Typos in the publisher server name or database name also trigger this exact error message.
How to diagnose and fix the failure safely
Start by checking the exact publisher name and database name in your error log. Compare those names against the replication metadata on your distributor instance. Often, a script passes the secondary node name instead of the original publisher name.
If the names match, check whether the redirection step ever ran on the distributor. You must set up the redirection mapping before you run validation checks against it. Once you register the redirected target, the validation check will pass without error 21871.
Kubernetes API Server Access + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Keep permissions tight while your team investigates the distributor and publisher instances. Do not grant the fixed database owner role just to let someone check replication state. Members of that owner role can change all settings and even drop the database.
Use the fixed data reader role when an engineer only needs to inspect user tables. That role lets a user read all user tables and views without write rights. Note that you cannot change the permissions assigned to fixed database roles.
Managing logins and users across replication nodes
Replication topologies span multiple servers, so user identity setup matters during a failover. A database user represents the identity of a login when it connects to a database. For access to many databases on an instance, a login in master is common.
When a person needs access to just one or a few databases, consider contained users. A contained database user has a password and does not tie to a master login. An admin must enable contained databases on the server and database first.
Using contained users or Least Privilege roles keeps failover checks safe from accidental writes. If you must block someone from changing tables, use the deny data writer role. You can also block table reads by adding the user to the deny reader role.
Govern SQL Server queries and responses in flight
Table grants decide which SQL Server objects a caller may touch. They do not check query intent or rewrite sensitive values in results across every client and agent. By design, hoop.dev sits inline in the TDS wire protocol next to SQL Server as a sidecar for your SQL Server. On every production batch from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for approval.
With hoop.dev guardrails and hoop.dev data masking, banned statements are refused or held for review, matched sensitive fields in supported result columns are masked in memory, and each decision is logged. Check out the code on GitHub.
Frequently asked questions
What does severity 16 mean for message 21871?
Severity 16 indicates a general error that the user or admin can correct. It does not indicate a crash, disk corruption, or a system outage. You resolve it by fixing the publisher name or adding the missing redirection record.
Why does my validation check fail with error 21871 after a failover?
Validation fails when the distributor server has no redirection entry for that publisher and database. Make sure you pass the original publisher name to the check, not the replica name. If the entry is missing, add the redirection mapping on the distributor first.
Should engineers use the database owner role to check replication tables?
No, the database owner role grants full control and lets a user drop the database. Grant read access through the fixed data reader role when inspecting user tables instead. Keep write steps in peer-reviewed scripts so operators do not run raw admin commands.
Related guides
In this post