SQL Server error 957 means the database you are trying to use is still enabled for database mirroring, so the operation you attempted (such as restoring, detaching, or dropping the database) is blocked. The fix is to remove the mirroring configuration first, then retry your original task. In most cases you will run a few ALTER DATABASE statements to turn off mirroring and remove the partner, and the error clears.
What You'll Need
- SQL Server Management Studio (SSMS) or another client that can connect to the instance.
- Membership in the sysadmin fixed server role, or at least ALTER ANY DATABASE and CONTROL SERVER permissions on the database in question.
- The name of the database that is throwing error 957.
- Knowledge of whether the mirroring session is still active or was left behind after a failover or partner removal.
Step-by-Step
- Confirm the database is mirrored. Connect to the server in SSMS, open a new query window, and run:
SELECT name, mirroring_state_desc, mirroring_role_desc, mirroring_partner_name FROM sys.database_mirroring WHERE mirroring_state IS NOT NULL;
If the database appears with a state such as SYNCHRONIZED, SYNCHRONIZING, or SUSPENDED, mirroring is still configured. If the row shows NULL for the state, mirroring is already off and the error may be coming from a different database or a stale configuration. - Check that you are in the right database context. Error 957 is database-specific. Run
USE [YourDatabaseName];and thenSELECT DB_NAME();to confirm you are targeting the database that is actually mirrored. A common cause is running the command against a restored copy that inherited mirroring metadata. - Remove the mirroring partner. In the same query window, run:
ALTER DATABASE [YourDatabaseName] SET PARTNER OFF;
This ends the mirroring session and removes the partner. If the partner server is offline, this statement may still succeed because it operates on the local metadata. If it fails because the partner is unreachable, proceed to the next step. - Turn off mirroring explicitly. Run:
ALTER DATABASE [YourDatabaseName] SET MIRRORING OFF;
This clears the mirroring configuration on the database. In some SQL Server versions, SET PARTNER OFF is enough; in others, the explicit MIRRORING OFF is needed to fully reset the state. - Verify the mirroring state is cleared. Re-run the query from step 1. The database should no longer appear, or its mirroring_state_desc should be NULL. You can also check
sys.database_mirroringfor the specific database name. - Retry your original operation. Now run the restore, detach, drop, or rename that produced error 957. For a restore, use
RESTORE DATABASE [YourDatabaseName] FROM DISK = 'C:\Backups\YourDatabase.bak' WITH REPLACE;if you intend to overwrite. For a detach, useEXEC sp_detach_db 'YourDatabaseName';. - If the database is a restored copy, drop and restore again. When you restore a database that was mirrored, the mirroring metadata can be carried over. If the steps above do not clear it, drop the database (after confirming you have a backup) and restore it fresh with
WITH REPLACE, then verify mirroring is off before using it.
Common Mistakes
- Running the ALTER DATABASE statements against master or another database instead of the mirrored one. Always confirm the context with
SELECT DB_NAME();. - Assuming the error means the database is currently participating in an active mirroring session. It can also appear when mirroring was configured in the past and the metadata was not cleaned up.
- Forgetting that a restored database inherits mirroring settings. If you restore over an existing mirrored database, the mirroring state may persist until you explicitly turn it off.
- Trying to detach or drop the database before removing the partner. SQL Server blocks these operations while mirroring is enabled.
- Using the wrong database name in the ALTER statement, especially when the database name contains spaces or special characters. Use square brackets around the name.
Tips
- Run
SELECT * FROM sys.database_mirroring;to see all databases and their mirroring states at a glance. This helps you spot other databases that may have leftover mirroring configuration. - If you are decommissioning a mirror, remove the partner on both the principal and mirror servers to avoid orphaned metadata.
- Script the cleanup steps and keep them with your backup and restore procedures so the same issue does not surprise you during a recovery.
- Check the SQL Server error log for messages about mirroring before and after the change. It can confirm whether the partner was contacted or the session was already broken.
- When restoring a database that was mirrored, use
WITH REPLACEonly after verifying you have a valid backup, because it overwrites the existing database.
Troubleshooting
If ALTER DATABASE ... SET PARTNER OFF fails with a timeout or connection error, the partner server may be offline or unreachable. In that case, try ALTER DATABASE [YourDatabaseName] SET MIRRORING OFF; directly. If that also fails, check that you have the required permissions and that the database is not in a restoring state. You can also use ALTER DATABASE [YourDatabaseName] SET PARTNER SUSPEND; to pause the session, then remove the partner once connectivity is restored.
If error 957 persists after running the ALTER statements, verify that you are connected to the correct instance and that the database name is spelled exactly as it appears in sys.databases. In rare cases, the mirroring metadata may be corrupted; restoring the database from a backup taken before mirroring was configured is the safest way to reset it. Always take a fresh backup before attempting any destructive step.
If you are trying to drop the database and it is the principal in a mirroring session, you must remove the mirroring configuration first. The same applies to detaching. If the database is the mirror, you can remove the partner from the principal side, or run the ALTER statements on the mirror after breaking the session.
Frequently Asked Questions
What does SQL Server error 957 mean exactly?
It means the database is still enabled for database mirroring, so SQL Server refuses an operation that requires the database to be standalone, such as restore, detach, or drop.
Can I ignore error 957 and continue?
No. The operation will not complete until mirroring is turned off. You must remove the mirroring configuration first.
Does turning off mirroring delete my data?
No. Turning off mirroring only changes the mirroring configuration. Your data remains intact. However, if you then restore or drop the database, those operations can affect data, so take a backup first.
Why does the error appear on a database I just restored?
Restoring a database that was mirrored can carry over the mirroring metadata. The restored copy may still be flagged as mirrored until you run the ALTER statements to clear it.
Do I need to run the commands on both servers?
If the mirroring session is still active, removing the partner on the principal server is usually enough. For a clean decommission, run the steps on both the principal and mirror to avoid leftover configuration.
What permissions do I need to fix error 957?
You need ALTER permission on the database and, depending on the operation, CONTROL SERVER or membership in the sysadmin role. If you are unsure, ask your database administrator.