SQL Server Error 941 occurs when the database engine cannot open a database because the underlying data files (.mdf or .ndf) or log files (.ldf) are missing, corrupted, or inaccessible. To fix this, you must ensure the files exist in the expected directory and that the SQL Server service account has full NTFS permissions to access those folders. If the files are physically missing, you must restore the database from a backup or attach the files from a known good location.
What You'll Need
- Administrative access to the server hosting the SQL Server instance.
- SQL Server Management Studio (SSMS) installed and configured.
- Access to the file system where the database files (.mdf and .ldf) are stored.
- A recent database backup (if the files are corrupted or permanently lost).
- Knowledge of the SQL Server service account name (e.g., NT Service\MSSQLSERVER).
Step-by-Step
- Identify the Missing File: Open SQL Server Management Studio (SSMS) and connect to your instance. Check the Error Log by navigating to Management > SQL Server Logs. Look for the specific entry associated with Error 941. The log will explicitly state which file (the primary data file or the transaction log) the system is unable to locate or open. This prevents you from guessing which file is causing the failure.
- Verify Physical File Existence: Navigate to the folder path indicated in the error log or the default SQL Server data directory. Check if the .mdf (Master Data File) and .ldf (Log Data File) files are actually present. If you recently moved the database files to a different drive or folder without updating the system metadata, the server will trigger Error 941 because it is looking in the old location.
- Correct Folder Permissions: Right-click the folder containing the database files and select Properties > Security. Ensure that the account running the SQL Server service has "Full Control" permissions. If the service is running under a local system account or a specific domain account, that specific identity must have read/write access to the folder. Without these permissions, the engine sees the file but cannot "open" it, resulting in the 941 error.
- Detach and Re-attach the Database: If the files exist but the database is stuck in a "Recovery Pending" or "Suspect" state, try detaching it. Right-click the database in SSMS, select Tasks > Detach. Once detached, right-click the "Databases" folder and select Attach. In the Attach Databases dialog, click "Add" and browse to the correct location of the .mdf file. If the .ldf file is missing or in a different spot, you can click the "..." button next to the log file in the bottom pane to point to the correct path.
-
Force Attach (If Log File is Missing):
If the .mdf file is present but the .ldf file is permanently lost, you can attempt to rebuild the log. Use the following T-SQL command in a New Query window:
CREATE DATABASE [YourDatabaseName] ON (FILENAME = 'C:\Path\To\YourFile.mdf') FOR ATTACH_REBUILD_LOG;Warning: This should only be done as a last resort, as it may result in the loss of transactions that were not yet hardened to the data file. - Restore from Backup: If the files are corrupted beyond repair or cannot be found, the safest path is a full restore. Right-click Databases > Restore Database. Select "Device" and locate your most recent .bak file. Ensure that the "Relocate files" option is checked in the Files tab if you are restoring to a different server or directory than the original source.
Common Mistakes
One of the most frequent mistakes is attempting to fix the error by simply renaming the files in Windows Explorer. SQL Server tracks files by their internal logical names, not just the physical filename. Renaming a file on the disk without updating the system catalog via T-SQL will not resolve Error 941 and may complicate the recovery process.
Another common error is running SSMS as an Administrator but forgetting that the SQL Server Service itself runs under a different, less-privileged account. Granting permissions to your own user account does not help the database engine; you must grant permissions to the service account (e.g., NT Service\MSSQLSERVER or a specific domain service account).
Users also frequently attempt to attach a database using a file that is currently being used by another process, such as an antivirus scanner or a backup agent. If a third-party application has a lock on the .mdf file, SQL Server will report that it cannot open the database, mimicking the 941 error.
Tips
To prevent this error in the future, implement a strict file naming convention and document the physical paths of all production databases. Avoid placing database files in user folders (like C:\Users\Admin\Documents) because these folders have restrictive permissions that often change during Windows updates or profile migrations.
Always maintain a "Tail-Log Backup" strategy. If you encounter a situation where the data file is healthy but the log file is corrupted, having a tail-log backup allows you to recover the database to the exact moment of failure without relying on the risky ATTACH_REBUILD_LOG command.
Use a dedicated drive for your data (.mdf) and log (.ldf) files. This not only improves I/O performance but also makes it much easier to identify and manage the files during a recovery scenario, as you won't have to sift through system files on the C: drive.
Troubleshooting
If the database remains inaccessible after following the steps above, check the following scenarios:
Scenario A: The file is marked as Read-Only. This often happens when files are copied from a CD, DVD, or a read-only network share. Right-click the .mdf and .ldf files, go to Properties, and ensure the "Read-only" attribute is unchecked. SQL Server cannot open a database if it cannot write to the transaction log.
Scenario B: Disk failure or bad sectors. If the files exist but the error persists, run a check disk command (chkdsk) on the drive. If the OS reports bad sectors, the file may be physically corrupted. In this case, stop the SQL Server service immediately to prevent further damage and attempt to copy the files to a healthy drive before trying to attach them again.
Scenario C: The database is in a "Single User" mode. If another administrator is connected to the database in single-user mode, you may receive an error that the database cannot be opened. Run EXEC sp_configure 'show advanced options', 1; RECONFIGURE; and then check the current state of the database. You may need to kill the existing process ID (SPID) using the KILL [SPID] command to regain access.
Frequently Asked Questions
Can I fix Error 941 without a backup?
Yes, provided the .mdf file is intact. You can use the ATTACH_REBUILD_LOG command to recreate a missing log file, though you may lose the most recent unsaved transactions.
Does Error 941 mean my data is deleted?
Not necessarily. It usually means the path to the data is broken or the permissions are wrong. The data typically still exists in the .mdf file; the server just can't find or access it.
Why did this happen after a server migration?
This is common during migrations because the folder structure on the new server often differs from the old one, or the new service account lacks permissions to the migrated folders.
Will restarting the SQL Server service fix this?
Restarting may resolve the issue if the file was temporarily locked by another process, but it will not fix missing files or incorrect NTFS permissions.
Is there a difference between Error 941 and Error 5120?
They are closely related. Error 941 is a general "cannot open" message, while Error 5120 specifically points to an operating system error (usually permissions or missing files) preventing the access.