SQL Server error 948 means the database cannot be opened because it is offline, being recovered, or in a state that does not allow user connections. In practice, the fix is to bring the database back online with ALTER DATABASE ... SET ONLINE, or to restore it properly if the files are missing or the database is still restoring. You cannot repair this error by restarting the SQL Server service alone in most cases; the database state must be changed explicitly.
What You'll Need
- Membership in the
sysadminfixed server role, or at leastdbcreatorplus the ability to runALTER DATABASEon the affected database. - SQL Server Management Studio (SSMS) or Azure Data Studio, or a working
sqlcmdsession. - The exact database name from the error message.
- Access to the SQL Server error log and the Windows Event Viewer if the database is in recovery or suspect state.
- Recent backups if the database files are missing, damaged, or the database was dropped and needs to be reattached.
Step-by-Step
- Read the full error message. Error 948 is always followed by a state description such as "it is offline," "it is in recovery," "it is being restored," or "it is suspect." That trailing phrase tells you which fix applies. Write it down before doing anything else.
- Confirm the current state. In SSMS, connect to the instance, open a new query window, and run:
SELECT name, state_desc FROM sys.databases WHERE name = 'YourDatabaseName';
Thestate_desccolumn returns values such as ONLINE, OFFLINE, RECOVERING, RECOVERY_PENDING, SUSPECT, RESTORING, or EMERGENCY. This is the single most useful diagnostic step. - If the state is OFFLINE, bring it online. Run:
ALTER DATABASE [YourDatabaseName] SET ONLINE;
If the command succeeds, the database becomes available immediately. If it fails, read the new error; it usually points to a missing file or a permissions problem on the data or log file. - If the state is RECOVERING or RECOVERY_PENDING, wait and then investigate. Recovery can take seconds on a small database and hours on a large one. Check the SQL Server error log for messages about rollback or redo progress. Do not detach or restart the service while recovery is active unless you have no other option, because an interrupted recovery can leave the database in a worse state.
- If the state is RESTORING, the restore did not finish. A database left in RESTORING was restored WITH NORECOVERY (or the restore was interrupted). If you have the remaining backup files, complete the restore sequence, ending with
WITH RECOVERY. If you do not, restore the last full backup again and finish withWITH RECOVERY. - If the state is SUSPECT, treat it as a corruption or file-access problem. Check the SQL Server error log and Windows Event Viewer for I/O errors, disk full conditions, or permission failures on the .mdf and .ldf files. Confirm the SQL Server service account still has full control on the folder holding those files. Then attempt recovery from backup first; only use emergency-mode repair as a last resort, and only after taking a file copy of the .mdf and .ldf.
- If the database is missing entirely, attach or restore it. If the files still exist, use
CREATE DATABASE ... ON (FILENAME = '...') FOR ATTACH;or the Attach option in SSMS Object Explorer. If the files are gone, restore from your most recent backup. - Verify the fix. Re-run the state query from step 2 and confirm the value is ONLINE. Then run a simple
SELECTagainst a known table, and check that application connections succeed. Review the SQL Server error log one more time for lingering warnings.
Common Mistakes
- Restarting the SQL Server service and hoping. A restart does not change a database from OFFLINE to ONLINE, and on a RECOVERING database it can lengthen recovery or cause a rollback.
- Running
ALTER DATABASE ... SET ONLINEon a SUSPECT database. That command does not apply to suspect databases and will fail; you need to address the underlying I/O or corruption issue first. - Detaching a database in recovery. Detaching removes it from the instance and can make recovery harder to complete. Avoid detach unless a Microsoft support engineer or your documented procedure calls for it.
- Ignoring the state suffix in the error. Error 948 is a wrapper; the specific state determines the fix. Treating every 948 the same wastes time.
- Assuming the service account has permissions. After moving files, restoring to a new drive, or changing the service account, the SQL Server service account may lose access to the .mdf and .ldf files, producing error 948 with an access-denied message in the log.
Tips
- Always capture the exact error text and the
state_descvalue before changing anything; it makes troubleshooting far faster. - Keep the SQL Server error log open in a second window while you work. It records the real cause behind many 948 errors, including file path and permission problems.
- For large databases, schedule recovery checks during low-traffic windows; recovery can consume significant CPU and I/O.
- Maintain tested backups. Almost every 948 scenario that cannot be resolved with
SET ONLINEis resolved with a clean restore. - Document the state of each database after any restore or file move so future errors are easier to interpret.
Troubleshooting
If ALTER DATABASE ... SET ONLINE returns an error, read the accompanying message carefully. "Access is denied" or "operating system error 5" points to file permissions: confirm the SQL Server service account has full control on the folder containing the data and log files. "The system cannot find the file specified" means the .mdf or .ldf is missing or was moved; locate the files and attach them, or restore from backup. "The log cannot be rebuilt because there were open transactions" means the log file is missing or damaged; restore from backup rather than forcing a rebuild unless you accept possible data loss.
If the database is stuck in RECOVERING for an unusually long time, check for long-running transactions, insufficient disk space for the log, or a slow storage subsystem. If the state is SUSPECT, check Windows Event Viewer for disk errors and run DBCC CHECKDB only after the database is accessible in emergency mode; be aware that emergency-mode repair can cause data loss, so take a file copy of the .mdf and .ldf first. If none of these steps resolves the issue, restore the most recent verified backup.
Frequently Asked Questions
What does SQL Server error 948 actually mean?
It means the database exists in the instance but is in a state that does not permit user connections, such as OFFLINE, RECOVERING, RESTORING, or SUSPECT. The fix depends on which state applies.
Can I fix error 948 by restarting SQL Server?
Usually not. A restart does not bring an OFFLINE database online and can interrupt recovery. Use ALTER DATABASE ... SET ONLINE or complete the restore instead.
How do I check a database's current state?
Query sys.databases and read the state_desc column, or view the database in SSMS Object Explorer, which shows the state in the details pane.
What should I do if the database is SUSPECT?
Check the SQL Server error log and Windows Event Viewer for I/O or permission errors, verify the service account has access to the files, and restore from backup. Use emergency-mode repair only as a last resort and after copying the database files.
Will I lose data by setting the database online?
No. SET ONLINE only changes the database state; it does not modify data. Data loss risk comes from repairing a suspect database or rebuilding a missing log, not from bringing an offline database online.
Why does the error mention a state like "it is offline" or "it is in recovery"?
SQL Server appends the specific state to error 948 so you know which corrective action to take. Always read that suffix before choosing a fix.