SQL Server error 982 means the database you are trying to use is not currently available for access, and the fix is to bring it back online or repair its state. The full message usually reads "Unable to access the database because no" followed by a reason such as "the database is offline" or "the database is in a state that does not allow access." The shortest working set of steps is: connect to the instance with an administrator account, check the database state in SQL Server Management Studio (SSMS), and run the appropriate ALTER DATABASE statement to bring it online or recover it. This guide walks through that process, explains the common causes, and covers what to do when the simple fix does not work.

What You'll Need

  • An account with sysadmin or dbcreator rights on the SQL Server instance, or the ability to log in with the built-in sa account (or a Windows account in the local Administrators group, if SQL Server is configured to allow it).
  • SQL Server Management Studio (SSMS) or Azure Data Studio installed, or access to sqlcmd on the server itself.
  • The exact name of the database that is throwing the error.
  • Recent backups of the database, if you have them. Some repair steps can lose data, so confirm you have a backup before running anything that changes the database state.
  • Permission to restart the SQL Server service on the host, in case the instance itself needs a restart.

Step-by-Step

  1. Connect to the correct instance. Open SSMS and connect to the SQL Server instance that hosts the database, using an account with sysadmin rights. If you normally connect with a low-privilege account, switch to an administrative login for this work. Menu labels can differ slightly by SSMS version and region, but the connection dialog is the same across recent versions.
  2. Check the database state. In Object Explorer, expand Databases and look at the database name. If it is greyed out or marked with a status such as Offline, Recovery Pending, Suspect, Restoring, or Emergency, that is the cause. You can also run SELECT name, state_desc FROM sys.databases; in a new query window to see the state in text form.
  3. Bring an offline database back online. If the state is OFFLINE, run ALTER DATABASE [YourDatabaseName] SET ONLINE; and press Execute. Replace the bracketed name with the real database name. If the command succeeds, try connecting to the database again.
  4. Handle a database in recovery or restoring state. If the state is RECOVERY_PENDING or RESTORING, wait a few minutes and re-check. A restore in progress will block access until it finishes. If it stays stuck, check the SQL Server error log for the underlying message, because the state alone rarely tells you the cause.
  5. Check for a suspect database. If the state is SUSPECT, the database failed a consistency check or could not be recovered at startup. Run DBCC CHECKDB ([YourDatabaseName]) to see the errors. Do not run repair options until you have read the output and have a backup, because repairs can remove data.
  6. Confirm the database files exist and are accessible. Run SELECT name, physical_name FROM sys.master_files WHERE database_id = DB_ID('YourDatabaseName'); and check that each file path exists on disk and that the SQL Server service account has read and write access to the folder. A missing or locked file is a common cause of error 982 after a drive change or a restore to a different server.
  7. Restart the SQL Server service if the state will not change. In SQL Server Configuration Manager, open SQL Server Services, right-click the SQL Server (instance) service, and choose Restart. This briefly disconnects all users, so do it in a maintenance window if the instance is busy.
  8. Fix permissions if the error is about access, not state. If the database is ONLINE but your login still gets error 982, the login may be missing a user mapping in that database. Ask a sysadmin to check the database's users and roles, or to grant your login access with ALTER AUTHORIZATION or by recreating the user mapping. Do not grant sysadmin to a normal user just to work around this.
  9. Restore from backup as a last resort. If the database is corrupt beyond repair and you have a backup, restore it to a new database name first, verify the data, and then swap it in. Restoring over the existing database destroys its current contents, so confirm the backup is good and take a copy of the damaged files before you overwrite anything.

Common Mistakes

  • Running ALTER DATABASE ... SET ONLINE against the wrong database name. Always copy the name from sys.databases rather than typing it from memory.
  • Using a low-privilege login and assuming the error is about the database state, when it is really a permissions problem. Check the state first, then check permissions.
  • Running DBCC repair options without a backup. Repair can delete rows it cannot read, and there is no undo.
  • Restarting the whole server instead of just the SQL Server service, which takes longer and affects other services on the machine.
  • Ignoring the SQL Server error log. The state shown in SSMS is a summary; the log usually names the actual file or page that failed.
  • Forgetting that a restore or an index rebuild can hold the database in a non-accessible state for a long time on large databases.

Tips

  • Take a backup before any repair step, even if the database is already suspect. A file copy of the .mdf and .ldf files while the service is stopped is a cheap safety net.
  • Use SELECT name, state_desc, user_access_desc FROM sys.databases; to see both the state and whether the database is set to SINGLE_USER or RESTRICTED_USER, which can also block access.
  • Check disk space on the drive holding the database files. A full drive can push a database into recovery pending at startup.
  • Keep the SQL Server service account's permissions on the data folder consistent across moves and restores.
  • If the database is part of an Availability Group, a failover or a paused synchronization can leave it inaccessible. Check the group's state before running repair commands.

Troubleshooting

If ALTER DATABASE ... SET ONLINE fails, read the error message it returns; it usually names the file or the reason. If the database stays in RECOVERY_PENDING, check the error log for messages about missing log files or disk errors. If DBCC CHECKDB reports corruption, run it with the REPAIR_ALLOW_DATA_LOSS option only after a verified backup, and expect to lose some data. If the database is in an Availability Group, take it out of the group before repair work and add it back afterwards. If you cannot log in at all, start the instance in single-user mode from the command line with the -m flag and connect with sqlcmd, but note that this blocks other users. If none of this resolves the state, open a support case with Microsoft or your database administrator rather than experimenting on a production database.

Frequently Asked Questions

What does SQL Server error 982 actually mean?

It means the database is in a state that does not allow access, such as offline, suspect, recovery pending, or restoring. The message is a symptom; the state is the cause.

Can I fix error 982 without restarting SQL Server?

Often yes. Bringing an offline database online with ALTER DATABASE ... SET ONLINE does not require a restart. A restart is only needed when the state will not change.

Will repairing a suspect database lose data?

It can. Repair options may remove rows or pages that cannot be read, so always take a backup first and restore from it if the repair removes more than you can accept.

Why does error 982 appear only for one login?

If other logins can open the database, the database is online and the problem is permissions. The login is probably missing a user mapping or role membership in that database.

Does error 982 mean the database is corrupt?

Not necessarily. Offline and restoring states are normal and recoverable. Suspect and recovery pending states are more serious and should be investigated with DBCC CHECKDB and the error log.

Can I fix it from sqlcmd instead of SSMS?

Yes. The same ALTER DATABASE and DBCC statements work in sqlcmd. Connect with an administrative login and run the statements exactly as you would in SSMS.