Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

SQL Server Error 1459: How to Fix It

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

SQL Server error 1459, “An error occurred while accessing the database,” usually means SQL Server cannot read or write to the database files, often due to permission problems, a file being locked, or a corrupted page. Start by checking the Windows event log for the exact underlying error, then verify the SQL Server service account has full control over the database files and folder. Below are the steps to diagnose and fix it.

What You'll Need

  • Access to the SQL Server Management Studio (SSMS) or another query tool.
  • Windows administrator rights on the server (to check event logs and change file permissions).
  • Knowledge of the SQL Server service account name (usually shown in SQL Server Configuration Manager).
  • The physical path of the database files (.mdf and .ldf) — you can find this by running: SELECT physical_name FROM sys.master_files WHERE database_id = DB_ID('YourDB');

Step-by-Step

  1. Check the Windows Event Viewer. Open Event Viewer (eventvwr.msc), go to Windows Logs > Application, and look for recent errors from “MSSQLSERVER” or “SQL Server”. The error message often includes a more specific code or file name. Note the exact error text.
  2. Verify the database is online. In SSMS, right-click the database and select Properties > Options. If the state is “Restoring” or “Offline”, bring it online: right-click the database > Tasks > Bring Online. If it’s in “Suspect” mode, you may need to set it to Emergency mode (see Troubleshooting).
  3. Check file permissions. Using Windows Explorer, navigate to the folder containing the .mdf and .ldf files. Right-click the folder > Properties > Security. Ensure the SQL Server service account has “Full control” (or at least “Modify”) on the folder and the files. If not, click Edit > Add, enter the service account name, check “Full control”, and apply. Repeat for the files themselves.
  4. Confirm the service account is correct. Open SQL Server Configuration Manager, click SQL Server Services, and note the “Log On As” account for the SQL Server instance. Make sure that account is the one you gave permissions to in step 3.
  5. Check for file locks. Ensure no other process (like a backup tool, antivirus, or another SQL Server instance) is holding the database files. You can use Sysinternals Process Explorer to search for handles on the .mdf file. If locked, stop the conflicting process.
  6. Run DBCC CHECKDB. If the error persists, the database may be corrupted. In SSMS, run: DBCC CHECKDB('YourDB') WITH NO_INFOMSGS; This will report any corruption. If corruption is found, you may need to restore from a backup or use a repair option (see Troubleshooting).
  7. Restart the SQL Server service. In SQL Server Configuration Manager, right-click the SQL Server service and select Restart. This can clear transient locks or memory issues.
  8. Check disk space. Ensure the drive where the database files reside has free space. A full disk can cause error 1459. Right-click the drive in Windows Explorer and check free space.
  9. Review SQL Server error log. In SSMS, under Management > SQL Server Logs, open the current log. Look for messages around the time of the error that may give more detail, such as an operating system error code (e.g., “Operating system error 5 (Access is denied)”).
  10. Test with a simple query. Try a basic query like SELECT 1; against the database. If that works, the issue may be with a specific object; if not, the database is still inaccessible.

Common Mistakes

  • Giving permissions to the wrong account. The service account is often “NT Service\MSSQLSERVER” or “MSSQL$InstanceName”. Using your own user account instead will not help.
  • Only changing folder permissions, not file permissions. Sometimes the folder is fine but the individual .mdf file has restrictive ACLs. Check both.
  • Ignoring the event log. The event log often contains the real underlying error (like a specific file path or OS error). Skipping it can lead to guessing.
  • Running DBCC CHECKDB on a suspect database without first bringing it to emergency mode. DBCC may fail if the database is not accessible.
  • Restarting the service without checking for external locks. If a backup agent is still running, the restart may not help.

Tips

  • Always take a full backup before attempting any repair (if the database is accessible).
  • Use the “WITH NO_INFOMSGS” option in DBCC to reduce output.
  • If you have multiple instances, ensure you are looking at the correct SQL Server service in Configuration Manager.
  • Consider using SQL Server’s built-in “sa” account for troubleshooting, but only if you know the password and it’s allowed by your policy.
  • Document the exact error text from the event log — it will help if you need to contact Microsoft Support.

Troubleshooting

If the database is marked as “Suspect”:

  1. Set the database to Emergency mode: ALTER DATABASE YourDB SET EMERGENCY;
  2. Then run DBCC CHECKDB('YourDB') WITH NO_INFOMSGS; to see the extent of corruption.
  3. If repair is possible, run DBCC CHECKDB('YourDB', REPAIR_ALLOW_DATA_LOSS); — this can cause data loss, so only use it if you have no backup or are willing to lose recent changes.
  4. After repair, set the database back to MULTI_USER: ALTER DATABASE YourDB SET MULTI_USER;

If the error is “Operating system error 5 (Access is denied)”: That is a permission issue. Recheck the service account and file ACLs. Also check if the folder is on a network share — SQL Server may not support network drives for database files.

If the error is “Operating system error 32 (file in use)”: Another process has the file open. Use Process Explorer to find which process and stop it.

If the error persists after all steps: Restore the database from the last good backup. If you don’t have a backup, you may need to contact a specialist or Microsoft Support.

Frequently Asked Questions

What does error 1459 mean exactly?

It means SQL Server could not access the database files. The actual cause is usually in the accompanying error message in the event log or SQL Server error log.

Can I fix error 1459 without restarting SQL Server?

Yes, often fixing permissions or releasing a file lock resolves it without a restart. A restart is only needed if the service is in a bad state.

Will DBCC CHECKDB repair fix everything?

No. It can fix certain types of corruption, but if the issue is permission or file lock, DBCC won’t help. Also, repair with data loss can remove some data.

How do I know which account to give permissions to?

Open SQL Server Configuration Manager, select SQL Server Services, and look at the “Log On As” column for your instance. That is the account.

What if the database is on a different drive than the default?

That’s fine. Just make sure the service account has access to that drive and folder. SQL Server does not support network or mapped drives for database files.

Is there a way to prevent this error?

Regularly check disk space, maintain proper file permissions, and avoid running third-party tools that might lock files. Also, keep your backups current.