This article guides to resolve,
How to resolve Microsoft SQL Server, Error: 5120? | How to resolve CREATE DATABASE failed. Some file names listed could not be created.
Sometimes you will get below error while attaching SQL Server database MDF file. This error cause due to file access issue.
TITLE: Microsoft SQL Server Management Studio
Attach database failed for Server ‘Server Name’. (Microsoft.SqlServer.Smo)
An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)
Unable to open the physical file “C:\Omkar\backups\StackOverflow2013_201809117\StackOverflow2013_1.mdf”.
Operating system error 5: “5(Access is denied.)”.
CREATE DATABASE failed. Some file names listed could not be created.
Check related errors. (Microsoft SQL Server, Error: 5120)
This issue occurred because there is permission issue to user trying to attach database file on SQL Server. We copy MDF files from different server and try to attach it on SQL Server. In that case permission is missing on file for SQL Service account where you trying to attach.
How to resolve this issue?
Grant permission to file trying to attach on SQL Server.
You have to grant full access on file for SQL Server Service account. You will find SQL Service account name in SQL Server Configuration Manager.
Once permission granted try to attach file and you will be successfully able to attach database.