Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1416: Database Not Configured for Mirroring

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 1416 means the database you are trying to use in a mirroring session has not been configured for mirroring on that server instance. The fix is to run the mirroring setup on the principal, mirror, and witness (if used) in the correct order, making sure each database is in the FULL recovery model, has a recent full backup and log backup, and that the mirror database has been restored WITH NORECOVERY. Once all three endpoints exist and the partner addresses are correct, the error disappears and the session can start.

What You'll Need

  • SQL Server Management Studio (SSMS) or sqlcmd connected to each server instance with sysadmin rights.
  • The exact server and instance names for the principal, mirror, and optional witness, plus the TCP port each will use for mirroring.
  • A full backup and at least one log backup of the principal database, plus the ability to copy those files to the mirror server.
  • Firewall rules allowing the mirroring port between the servers.
  • A database that is not already in an Availability Group or log shipping; mirroring and those features conflict.

Step-by-Step

  1. Confirm the database is not already in a mirroring session. On the principal, run SELECT DB_NAME(database_id), mirroring_state_desc FROM sys.database_mirroring WHERE mirroring_guid IS NOT NULL;. If the database appears with a state other than NULL, remove the existing session first with ALTER DATABASE [YourDB] SET PARTNER OFF; and wait for the mirror to catch up before continuing.
  2. Set the recovery model to FULL on the principal. Run ALTER DATABASE [YourDB] SET RECOVERY FULL;. Mirroring requires the full recovery model; simple or bulk-logged will block configuration.
  3. Take a full backup and a log backup of the principal. Use BACKUP DATABASE [YourDB] TO DISK = 'C:\Backup\YourDB_full.bak' WITH INIT; then BACKUP LOG [YourDB] TO DISK = 'C:\Backup\YourDB_log.trn' WITH INIT;. Copy both files to the mirror server.
  4. Restore the database on the mirror WITH NORECOVERY. On the mirror instance, run RESTORE DATABASE [YourDB] FROM DISK = 'C:\Backup\YourDB_full.bak' WITH NORECOVERY, REPLACE; followed by RESTORE LOG [YourDB] FROM DISK = 'C:\Backup\YourDB_log.trn' WITH NORECOVERY;. If the database name or file paths differ on the mirror, use WITH MOVE in the restore. Do not recover the database; it must stay in the restoring state.
  5. Create a database mirroring endpoint on each instance. On principal, mirror, and witness (if used), run CREATE ENDPOINT MirroringEndpoint STATE = STARTED AS TCP (LISTENER_PORT = 5022) FOR DATABASE_MIRRORING (ROLE = PARTNER);. On the witness, use ROLE = WITNESS instead. If an endpoint already exists, check it with SELECT name, role_desc, state_desc FROM sys.database_mirroring_endpoints;.
  6. Grant connect permission on the endpoints. For each service account, run GRANT CONNECT ON ENDPOINT::MirroringEndpoint TO [Domain\SqlServiceAccount]; on the instance where that account connects.
  7. Start the session on the mirror first. On the mirror instance, run ALTER DATABASE [YourDB] SET PARTNER = 'TCP://PrincipalServer:5022';. This is the step that most often raises error 1416 if the mirror database was recovered instead of left in NORECOVERY.
  8. Set the partner on the principal. On the principal, run ALTER DATABASE [YourDB] SET PARTNER = 'TCP://MirrorServer:5022';. The session should move to SYNCHRONIZED or SYNCHRONIZING.
  9. Add the witness if you need automatic failover. On the principal, run ALTER DATABASE [YourDB] SET WITNESS = 'TCP://WitnessServer:5022';. Without a witness, only manual failover is possible.
  10. Verify the state. Run SELECT DB_NAME(database_id), mirroring_state_desc, mirroring_role_desc, mirroring_safety_level_desc FROM sys.database_mirroring; on both servers. A healthy session shows SYNCHRONIZED on the principal and the mirror in the restoring state.

Common Mistakes

  • Restoring the mirror database without WITH NORECOVERY. If you see the database online on the mirror, error 1416 is almost guaranteed. Drop and restore again with NORECOVERY.
  • Running the principal's SET PARTNER before the mirror's. The mirror must be configured first.
  • Using the wrong endpoint port, a hostname that does not resolve, or a firewall blocking the mirroring port. Test connectivity with telnet or Test-NetConnection from each server.
  • Leaving the database in SIMPLE or BULK_LOGGED recovery. Mirroring will not start.
  • Forgetting the log backup after the full backup. The mirror will be out of sync and the session will not reach SYNCHRONIZED.
  • Using a database that is already in an Availability Group. Remove it from the AG before configuring mirroring.

Tips

  • Use fully qualified TCP addresses (TCP://server.domain.com:5022) to avoid name resolution surprises.
  • Keep the principal and mirror on the same SQL Server major version and edition; mirroring is not supported across all combinations.
  • Take regular log backups on the principal after mirroring is running; the log will grow otherwise.
  • Test failover during a maintenance window so you know the witness and endpoints behave as expected.
  • Document the endpoint ports and service account permissions; these are the usual culprits when a session breaks later.

Troubleshooting

If error 1416 persists after following the steps, check the mirror database state first with SELECT state_desc FROM sys.databases WHERE name = 'YourDB';. It must read RESTORING. If it reads ONLINE, restore it again WITH NORECOVERY. Next, confirm the endpoint is STARTED on both servers and that the service accounts have CONNECT permission. If the error changes to a connection or timeout error, the problem is network or firewall, not mirroring configuration. If you see error 1418 (endpoint unreachable), verify the port and hostname. If the session starts but stays DISCONNECTED, check the SQL Server error log on both instances for endpoint or login failures. When in doubt, remove the session with SET PARTNER OFF, restore the mirror again WITH NORECOVERY, and rebuild the configuration in the order above.

Frequently Asked Questions

What does error 1416 actually mean?

It means the database you referenced in a mirroring command has no mirroring configuration on that instance, usually because the mirror database was recovered or the endpoint and partner were never set up.

Can I fix it without restoring the database again?

Only if the mirror database is still in the RESTORING state. If it is online, you must drop and restore it WITH NORECOVERY.

Do I need a witness server?

No. A witness is only required for automatic failover. Without one, you can still fail over manually.

Does mirroring work with the SIMPLE recovery model?

No. The principal database must use the FULL recovery model.

Why does the mirror database show as restoring but the session still fails?

Check the endpoint state, the service account CONNECT permission, and that the partner addresses use the correct port and hostname.

Can I use mirroring on a database in an Availability Group?

No. Remove the database from the Availability Group before configuring database mirroring.