Msg 5123, Level 16, State 1, Line 1
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'c:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA\xxx.mdf'.
Msg 1802, Level 16, State 4, Line 1
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
This is how it was fixed on my machine:
- Fire up SysInternals Process Monitor
- Open the 'Filter' menu
- Click 'Filter...'
- From the first dropdown select 'Path' in the second dropdown select 'contains'.
- For the value enter '\data'
- Click the 'OK' button to add the filter.
- Retry the operation
- Open up one of the NAME NOT FOUND entries with a Detail of Access Denied.
- Click the Process tab
- Note the process is sqlsvr.exe and the user is NT Authority\Network Service
- Navigate to the Data directory in Windows Explorer
- Click the Security tab
- Click the 'Edit' Button
- On the Permissions for 'Data' click the 'Add' button.
- For the object name enter 'Network Service'
- Click 'OK'
- Disregard any errors regarding not being able to set the permissions on files.
- Retry the operation in Sql Server Management Studio and it should work!