This is the error that makes people check their own permissions, and their own permissions are fine. The statement cleared every check inside SQL Server; the operating system then refused the file operation, and the account it refused is the one the SQL Server service runs as. Whoever you are in the session, the file is created by the engine.
It also never travels alone. Msg 1802, CREATE DATABASE failed, follows it as the summary line, and which error precedes that summary tells you exactly how far the engine got. Both variants below were produced deliberately on a real instance for this post.
Three Messages, One Story
| What came back | What it means |
|---|---|
5133 directory lookup failed | The service account cannot even read the folder. It got refused at the door. |
5123 CREATE FILE encountered operating system error | The folder was visible, and creating or opening the file inside it was refused. One level deeper, same underlying cause. |
1802 CREATE DATABASE failed | The wrapper that follows either of the above. It carries no cause of its own; the line before it does. |
The operating system error number inside the message is the precise complaint: error 5 is access denied, error 3 is path not found. Between the SQL error and the OS error you know which folder to look at and what kind of refusal happened.
The Fix: Give the Service Account the Folder
First, confirm what account the engine actually runs as, because that is who needs the rights:
SELECT servicename, service_account
FROM sys.dm_server_services;
A default installation runs as the per-service account NT SERVICE\MSSQLSERVER. Grant it Modify on the folder you want the files in, from an elevated prompt:
icacls "D:\SQLData" /grant "NT SERVICE\MSSQLSERVER:(OI)(CI)M"
Or sidestep the question entirely: leave the FILENAME clause off and let the database land in the instance’s default data directory, which the service already owns. That is the correct answer more often than people expect, because a folder chosen ad hoc for one database is exactly the kind that nobody granted rights on.
CREATE DATABASE Reporting;
What Not To Do
- Do not run the SQL Server service as an administrator to make this stop. The service account’s narrow rights are a feature; widening the account to fix one folder trades a five-minute ACL for a permanent enlargement of what a compromised instance can reach.
- Do not grant Everyone on the data folder. The engine needs the rights, not the world. Grant the specific service account.
- Do not confuse this with a full disk. A full disk during file creation speaks with 1105 and its relatives once the database exists. Error 5 inside a 5123 is a permissions conversation.
Common Questions
I am an administrator on the machine. Why am I denied?
It works in the default data directory but fails on my D: folder. Why?
icacls grant above is the missing step.Does the same thing happen when attaching a database?
What does operating system error 3 mean instead of 5?
Related Scripts
- Get Database File Details, where every database on the instance keeps its files
- Get Disk Space, the volume-level view before you pick a folder
- Get Recent Error Log Entries, the chain around a failed create, without leaving SSMS
Leave a Reply