Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I get the below error running a CREATE DATABASE script...

CREATE FILE encountered operating system error 5(failed to retrieve text for this
error. Reason: 15105) while attempting to open or create the physical file 
'H:\TestDatabase.mdf'

I am logged in as sa, which is a sysadmin.

What am I missing?

CREATE DATABASE TestDatabase ON PRIMARY
( 
    NAME = N'TestDatabase',
    FILENAME = N'H:\TestDatabase.mdf' , 
    SIZE = 51200000KB , 
    FILEGROWTH = 1024KB
)
share|improve this question
    
If you want to see what OS error 5 means just open CMD an type net helpmsg 5 you will see what it means. Similar goes for all OS errors –  Shanky Sep 3 at 13:28

3 Answers 3

Don't put your database files on the root of any drive. All kinds of things go wrong here, especially if you have UAC enabled.

Create a subfolder, like H:\Data or H:\Log, and put the files there, making sure the SQL Server service account has read/write permissions. Or use the actual instance data/log folders, which should already be set up permissions-wise. You can change those, too, if they're currently in a not-so-optimal place (like somewhere on C: <shudder>).

(Also, your CREATE DATABASE command is missing a LOG ON specification, dictating where you should put your log file.)

share|improve this answer

Looks like a permissions is not given to the drive you are using to create database

from the link

ERROR_ACCESS_DENIED
5 (0x5)
Access is denied.

Try to create this database, where SQL Server service account will have adequate permissions like Data or Log Folder

share|improve this answer
    
Check this post –  vijayp Sep 3 at 12:18
2  
To be correct SQL Server service account must have read write permission on the folder where data file and log file is being kept. –  Shanky Sep 3 at 13:04
    
@Shanky edited my answer, Thanks :) –  vijayp Sep 3 at 13:20
2  
@K09 To the root of your H: drive? Absolutely not. –  Aaron Bertrand Sep 3 at 15:25
1  
<facepalm> Stop trying to create the file in the root of H:\ drive, have you read any of the comments or answers? And no, you don't add the service account as a SQL login. You make sure the service account has permissions, in Windows, on the folder where you're trying to create files. –  Aaron Bertrand Sep 3 at 19:46

The SQL Server Service account must have access to the location where you wish to put the files for the database. When SQL Server interacts with the file system or network resources, this is the account that it uses for authentication. The service account does not necessarily need access to SQL Server.

I suspect, however, that H:\ is a mapped drive. You cannot place database files on a mapped drive, they must be local (either direct attached, iSCSI or some other method).

share|improve this answer
1  
H:\ isn't necessarily mapped (I've had several Windows systems with many partitions on the local disk(s)). Besides, mapped drives and UNC paths have been supported under a trace flag since 2005, and I haven't tested mapped drives, but UNC at least has been supported without the trace flag since 2008 R2. –  Aaron Bertrand Sep 3 at 19:44

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.