SQL Server Error 1401: Database Mirroring Fix
In this article
SQL Server error 1401 means the database mirroring master thread could not start, so mirroring for that database is effectively down. The fix is to confirm the mirroring endpoints on both servers are STARTED, verify the service accounts have CONNECT permission on each other's endpoint, and check that the mirror database is in RESTORING state and the principal is not in a suspect or recovery-pending state. Only after those checks should you remove and re-create the mirroring partnership.
What You'll Need
- Sysadmin (or at least ALTER ANY DATABASE and CONTROL SERVER) rights on both the principal and mirror instances.
- SQL Server Management Studio (SSMS) or sqlcmd connected to both servers.
- The names of the mirroring endpoints, the service accounts for both SQL Server services, and the database name.
- Recent full and log backups of the principal database, in case you have to re-seed the mirror.
- A maintenance window: removing and re-creating the mirroring partnership briefly interrupts mirroring and can force a re-seed.
Menu and dialog labels in SSMS can differ slightly by version and region, so if a label does not match exactly, look for the closest equivalent.
Step-by-Step
- Read the actual error in the log. In SSMS, open Object Explorer, expand Management > SQL Server Logs, and open the current log. Error 1401 is often preceded by a more specific message, such as a login failure for the service account or an endpoint state problem. Note the exact text before changing anything.
- Check the mirroring endpoint state on both servers. Run this on the principal and again on the mirror:
SELECT name, state_desc, role_desc, type_desc FROM sys.database_mirroring_endpoints;
The endpoint should show STATE = STARTED. If it shows STOPPED, start it withALTER ENDPOINT <endpoint_name> STATE = STARTED;. - Confirm the endpoint exists at all. If the query returns no rows, the endpoint was never created or was dropped. Create one with
CREATE ENDPOINT <endpoint_name> STATE = STARTED AS TCP (LISTENER_PORT = 5022) FOR DATABASE_MIRRORING (ROLE = ALL);on both servers, then grant CONNECT to the other server's service account. - Verify permissions on the endpoint. The service account of the principal must be able to connect to the mirror's endpoint, and vice versa. Check with
SELECT ep.name, sp.name FROM sys.server_permissions p JOIN sys.database_mirroring_endpoints ep ON p.major_id = ep.endpoint_id JOIN sys.server_principals sp ON p.grantee_principal_id = sp.principal_id WHERE p.permission_name = 'CONNECT';If the other server's account is missing, grant it:GRANT CONNECT ON ENDPOINT::<endpoint_name> TO [DOMAIN\account];. - Check the database states. On the mirror, the database must be in RESTORING. Run
SELECT name, state_desc FROM sys.databases WHERE name = '<database_name>';. If it shows ONLINE or RECOVERY_PENDING, the mirror is not ready. Restore the latest full backup WITH NORECOVERY, then the log backups WITH NORECOVERY, in order. - Look for a suspect or recovery-pending principal. On the principal, the same query should show ONLINE. If it shows SUSPECT or RECOVERY_PENDING, fix that first; mirroring cannot start while the principal is unhealthy. Restore from backup or run DBCC CHECKDB as appropriate before re-enabling mirroring.
- Confirm the mirroring partnership settings. Run
SELECT database_id, mirroring_role_desc, mirroring_state_desc, mirroring_partner_name FROM sys.database_mirroring WHERE database_id = DB_ID('<database_name>');on both sides. If the partner names do not match or the state is DISCONNECTED, the partnership is broken; continue to the next step. - Remove and re-create the partnership. On the mirror, run
ALTER DATABASE <database_name> SET PARTNER OFF;. On the principal, run the same. Then on the mirror, point it at the principal:ALTER DATABASE <database_name> SET PARTNER = 'TCP://<principal_server>:5022';. On the principal, point it at the mirror:ALTER DATABASE <database_name> SET PARTNER = 'TCP://<mirror_server>:5022';. Watch the SQL Server log on both sides for new errors as you do this. - Verify mirroring is running. Re-run the query from step 7; the state should read SYNCHRONIZED (high-safety) or SYNCHRONIZING, and the roles should show PRINCIPAL and MIRROR correctly. Check the log again for error 1401; it should no longer appear.
Common Mistakes
- Granting CONNECT to the wrong account. The grant must be to the service account that SQL Server actually runs under, not the login you use in SSMS.
- Forgetting that both servers need the endpoint, not just the principal.
- Restoring the mirror database WITH RECOVERY instead of WITH NORECOVERY, which makes it unusable as a mirror.
- Re-creating the partnership without checking the log first, which hides the real cause and lets the error return.
- Assuming a firewall problem when the endpoint itself is STOPPED. Check the endpoint state before opening ports.
Tips
- Record the endpoint name, port and service account for each server in your runbook; most 1401 cases come down to one of those three.
- Use the SQL Server error log timestamps to line up the 1401 with any login or endpoint errors nearby.
- Test the endpoint with a simple
telnet <server> 5022from each side to rule out network blocking before changing SQL settings. - Keep recent backups before touching the partnership; removing it can trigger a full re-seed on large databases.
Troubleshooting
If error 1401 persists after the steps above, work through these in order:
- Restart the SQL Server service on both instances. This clears transient endpoint state problems and is the simplest first check.
- Confirm the SQL Server service account has log-on-as-service rights and is not locked out in Active Directory.
- Check Windows Firewall and any network ACLs allow TCP 5022 (or your chosen port) in both directions.
- Look for a certificate or encryption mismatch if you use certificate-based endpoints; both endpoints must trust each other's certificates.
- If the mirror database is large, allow time for the re-seed after re-creating the partnership, and watch the log for progress rather than assuming failure.
If none of this resolves it, capture the full error log from both servers and the output of the endpoint and mirroring queries, and escalate to your DBA or Microsoft support. Do not drop and recreate databases as a first response; that risks data loss.
Frequently Asked Questions
What does error 1401 actually mean?
It means SQL Server could not start the database mirroring master thread for that database, so mirroring cannot run. The underlying cause is usually an endpoint, permission or database state problem rather than the error number itself.
Can I fix it without restarting SQL Server?
Often yes. Checking the endpoint state, permissions and database state and then re-creating the partnership usually resolves it. Restarting the service is a fallback, not the first step.
Will fixing 1401 cause data loss?
Not if the principal is healthy and you have backups. Removing the partnership can force a re-seed of the mirror, which takes time but does not lose principal data. Restoring the wrong backup over the principal would lose data, so avoid that.
Does error 1401 affect the principal database?
The principal can remain online and usable while mirroring is down, but you lose the redundancy. Treat it as urgent if high availability matters.
Do both servers need the same endpoint name?
No, the names can differ, but the port and the CONNECT permissions must be correct on both sides for the partnership to work.