SQL Server error 924 (“database is already open and can only”) means the database you are trying to open, attach, or restore is already mounted by the instance, so the operation is rejected. The fastest fix is to stop issuing a second open command: check which database name is already in use, then either connect to that existing database or detach it properly before retrying. In most cases the error appears when a script runs CREATE DATABASE ... FOR ATTACH or a restore against a database that is already online, or when a duplicate database name collides with an existing one.

What You'll Need

  • Access to SQL Server Management Studio (SSMS) or another client such as Azure Data Studio, signed in with an account that can view databases and run DBCC commands (sysadmin or dbcreator is typical).
  • The exact database name from the error message, and the physical file paths if you were attaching or restoring.
  • Permission to take the database offline or detach it if that turns out to be the right fix — and a current backup before you do.

Step-by-Step

  1. Read the full error text. Error 924 is usually paired with a second message that names the database and sometimes the file. Write down that name; you will use it in every step below.
  2. List the databases on the instance. In SSMS, expand the server node and then Databases, or run SELECT name, state_desc FROM sys.databases;. Look for a row matching the name in the error.
  3. Decide which situation you are in. If the database is listed and its state is ONLINE, it is already open — you do not need to attach or create it again. If it is listed but SUSPECT, RECOVERY_PENDING, or RESTORING, it is mounted but not usable, and that is a different repair job (see Troubleshooting).
  4. If you were attaching a copy of an existing database, rename the new one. You cannot attach a second copy under the same logical name. Use a different database name in your CREATE DATABASE ... FOR ATTACH statement, or attach it to a different instance.
  5. If you were restoring over a live database, use WITH REPLACE only after a backup. A restore to an existing database normally requires the database to be offline or the restore to specify replacement. Take a full backup first, then run the restore with the replace option if that is genuinely what you intend.
  6. If the database is genuinely stuck, take it offline and back online. Run ALTER DATABASE [YourDb] SET OFFLINE WITH ROLLBACK IMMEDIATE; then ALTER DATABASE [YourDb] SET ONLINE;. The rollback clause ends other sessions, so do this in a maintenance window.
  7. If you need to move or re-attach the files, detach it first. Run EXEC sp_detach_db 'YourDb'; only when no one is using it. Detaching removes the database from the instance but leaves the data and log files on disk, so it is reversible by re-attaching.
  8. Retry your original command. Run the attach, restore, or create statement again and confirm it completes without error 924.

Common Mistakes

  • Running the attach script twice. The first run succeeds, the second produces 924 because the database is now open.
  • Attaching a second copy of the same files under the same logical name instead of giving the copy a new name.
  • Using WITH ROLLBACK IMMEDIATE on a production database during business hours without warning users — it terminates their sessions.
  • Detaching a database that is being mirrored, log-shipped, or is a replication publisher; those configurations can block detach or leave things broken.
  • Assuming 924 means corruption. It is a state conflict, not a damage message; do not start repair commands before checking the state.

Tips

  • Query sys.databases before any attach or restore script so you know whether the name is already taken.
  • Use distinct logical names for test copies, for example appending a date or environment suffix.
  • Keep the physical file paths identical to the original when re-attaching, or use WITH MOVE to point at the correct folders.
  • Take a backup before detaching, restoring, or forcing a database offline. Detach itself is safe for the files, but a backup protects you from mistakes in the next step.
  • Menu labels in SSMS and Azure Data Studio can differ slightly by version, so rely on the T-SQL statements above when the UI wording does not match.

Troubleshooting

If error 924 persists after the steps above, work through these checks in order.

  1. Confirm the state again. Re-run SELECT name, state_desc FROM sys.databases;. A database stuck in RECOVERY_PENDING often needs its files checked or a restore from backup rather than another attach attempt.
  2. Check for an orphaned attach. If the database appears in sys.databases but you cannot connect, try ALTER DATABASE [YourDb] SET ONLINE; on its own.
  3. Look at the SQL Server error log. In SSMS, expand Management then SQL Server Logs, or read the current error log, for messages that appeared at the same time as 924. They usually name the real blocker.
  4. Restart the SQL Server service only if the instance is otherwise idle and you have approval; this clears transient state but disconnects all users.
  5. If the files are the problem, verify they exist at the paths in the error and that the SQL Server service account can read them. Permission problems often surface as attach failures that look similar.

Frequently Asked Questions

Does error 924 mean my database is corrupted?

No. It means the database is already open on the instance. Corruption messages use different error numbers and usually mention consistency or I/O problems.

Can I attach the same database files to two instances at once?

No. A set of data and log files can be attached to only one instance at a time. Copy the files and attach the copy under a new name if you need a second instance to use them.

Is it safe to detach a database to clear the error?

Detaching is safe for the files and can be reversed by re-attaching, but it takes the database offline for users. Back up first and do it in a quiet period.

Why does the error come back after I fix it?

Usually because the same script runs again on a schedule or in a deployment pipeline. Add a check against sys.databases before the attach or create statement.

Do I need sysadmin to fix error 924?

Not always. Viewing databases needs limited permission, but taking a database offline, detaching it, or restoring with replace typically requires elevated rights such as sysadmin or dbcreator.