SQL Server Error 1404: Database Mirror Fix Guide
In this article
SQL Server error 1404 means the command you issued against a mirrored database could not complete because the mirroring session is not in a state that allows it. The fix is to check the mirroring state on both partners, bring the principal and mirror back to SYNCHRONIZED or at least CONNECTED, and then retry the command. You cannot force a schema change, backup, or failover through a session that is paused, disconnected, or still synchronizing.
What You'll Need
- SQL Server Management Studio (SSMS) or sqlcmd connected to both the principal and mirror server instances.
- Membership in the sysadmin fixed server role or the db_owner role on the database, plus ALTER ANY DATABASE permission for mirroring changes.
- The database name and the mirroring endpoint names on both servers.
- Network access on the mirroring endpoint port (typically 5022) between the two servers.
- A recent full and log backup of the principal database before making any changes.
Step-by-Step
- Identify the current mirroring state. On the principal, run
SELECT DB_NAME(database_id) AS db, mirroring_state_desc, mirroring_role_desc, mirroring_safety_level_desc FROM sys.database_mirroring WHERE mirroring_guid IS NOT NULL;. Note whether the state is SYNCHRONIZED, SYNCHRONIZING, SUSPENDED, DISCONNECTED, or PENDING_FAILOVER. Error 1404 usually appears when the state is not SYNCHRONIZED or when the mirror is disconnected. - Check the mirror server. Run the same query on the mirror instance. If the mirror shows DISCONNECTED, the two partners cannot talk. If it shows SUSPENDED, someone or a failover operation paused the session.
- Verify the endpoint is listening. On each server, run
SELECT name, state_desc, port, type_desc FROM sys.database_mirroring_endpoints;. The state should be STARTED. If it is STOPPED, start it withALTER ENDPOINT <endpoint_name> STATE = STARTED;. - Test network connectivity. From each server, use
telnet <other_server> 5022or PowerShellTest-NetConnection -ComputerName <other_server> -Port 5022. If the port is blocked, fix the firewall rule or the endpoint port conflict before continuing. - Resume a suspended session. On the principal, run
ALTER DATABASE <database_name> SET PARTNER RESUME;. If the mirror is disconnected, this may fail; move to the next step. - Reconnect a disconnected mirror. On the principal, run
ALTER DATABASE <database_name> SET PARTNER RESUME;first. If it still shows DISCONNECTED, on the mirror runALTER DATABASE <database_name> SET PARTNER RESUME;and then on the principal runALTER DATABASE <database_name> SET PARTNER REDO_QUEUE;only if the redo queue is the blocker. Wait for the state to change to SYNCHRONIZING, then SYNCHRONIZED. - Check for a pending failover. If the state is PENDING_FAILOVER, complete or cancel it. On the principal, run
ALTER DATABASE <database_name> SET PARTNER FAILOVER;only if you intend to fail over. To cancel, runALTER DATABASE <database_name> SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS;only as a last resort and only after reading the warning in Troubleshooting. - Retry the original command. Once the state is SYNCHRONIZED (or at least SYNCHRONIZING with no errors), re-run the statement that produced error 1404. If it still fails, capture the full error text and check the SQL Server error log on both partners for endpoint or login failures.
- Confirm the fix. Re-run the state query from Step 1 and verify mirroring_state_desc is SYNCHRONIZED. Then run a small test command such as
ALTER DATABASE <database_name> SET RECOVERY FULL;(if already FULL, use a harmless metadata change) to confirm the session accepts commands.
Common Mistakes
- Running
SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSSwithout understanding that it can lose transactions and break the mirroring partnership; it is not a routine fix for error 1404. - Forgetting that the mirror database must be in RESTORING state before you configure mirroring; if it is ONLINE, mirroring setup fails.
- Changing the principal database recovery model to SIMPLE while mirroring is active; mirroring requires FULL recovery model.
- Assuming the error is about permissions when it is almost always about session state; check the state query first.
- Restarting SQL Server on one partner without checking whether the other partner is still waiting; this can leave the session suspended.
Tips
- Keep the mirroring endpoint port consistent and documented; mismatched ports are a common cause of DISCONNECTED states.
- Monitor mirroring state with a SQL Agent job or a scheduled query so you catch SUSPENDED or DISCONNECTED sessions before a command fails.
- Take a log backup on the principal before any manual failover or resume operation so you can recover if the session breaks.
- Use the same collation and compatibility level on both partners; mismatches can cause commands to fail even when mirroring looks healthy.
- When testing failover, use a maintenance window and verify the application connection strings point to the correct partner.
Troubleshooting
If the state query returns DISCONNECTED after you resume, check the SQL Server error log on both partners for messages about the endpoint, login failures, or certificate mismatches. A common cause is that the mirroring endpoint was dropped or recreated with a different port. Recreate the endpoint with the same port and restart the mirroring session.
If the state is SYNCHRONIZING but never reaches SYNCHRONIZED, the redo queue may be growing. Check SELECT redo_queue_size FROM sys.database_mirroring WHERE database_id = DB_ID('<database_name>');. A large or growing redo queue means the mirror cannot keep up; reduce load on the principal or add resources to the mirror.
If you see error 1404 together with error 1418 (server network address cannot be reached), fix the network or endpoint first; the mirroring state will not recover until the partners can communicate.
Warning: ALTER DATABASE <database_name> SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS; forces the principal to accept commands even if the mirror is unavailable, but it can cause data loss and requires you to re-establish mirroring afterward. Use it only when you cannot restore the session and you accept the risk.
If none of the above works, remove and reconfigure mirroring: on the principal run ALTER DATABASE <database_name> SET PARTNER OFF;, restore the latest full and log backups to the mirror with NORECOVERY, and reconfigure the partners. This deletes the mirroring configuration but not the database data; back up first.
Frequently Asked Questions
What does SQL Server error 1404 mean exactly?
It means the command failed because the database mirroring session is not in a state that permits the operation, typically because the session is suspended, disconnected, or still synchronizing.
Can I run schema changes while mirroring is SYNCHRONIZING?
Some commands are allowed, but many schema changes require the session to be SYNCHRONIZED. Wait for synchronization or check the specific command's requirements.
Does error 1404 always mean data loss?
No. It is a state error, not a data corruption error. Data loss is only a risk if you use FORCE_SERVICE_ALLOW_DATA_LOSS or if the mirror has fallen far behind.
How do I check mirroring state quickly?
Query sys.database_mirroring on both partners and look at mirroring_state_desc. SYNCHRONIZED is the healthy state for most commands.
Is error 1404 fixed by restarting SQL Server?
Not usually. Restarting can clear a transient network issue, but the mirroring session often remains suspended until you explicitly resume it.
What if the mirror database is in RESTORING state and I get 1404?
That is expected before mirroring is configured. Complete the mirroring setup with ALTER DATABASE ... SET PARTNER = 'TCP://...'; on both partners, then retry.