Error 5120 is a sharing violation of the files we are trying to open.
Possible reasons:
- Incorrectly configured path of MDF and LDF files
- Either of MDF or LDF files are missing
- Because the file is already attached to one of the existing databases on the server
Possible Solutions:
- When attaching the MDF file, remove the log file (assuming you have taken full back of the DB before detach and attach) by clicking on remove using UI
 or
 use SQL script
[cc lang=”TSQL”]
— Attaching MDF File without ldf file
CREATE DATABASE PubsDB ON
(FILENAME = N’D:\MSSQL\DATA\PubsDB.mdf’)
FOR ATTACH_REBUILD_LOG
GO
— if one file missing
CREATE DATABASE PubsDB ON
( FILENAME = N’D:\MSSQL\DATA\PubsDB.mdf’)
FOR ATTACH
GO
— recreate all log files
EXECUTE sp_attach_single_file_db @dbname = ‘PubsDB’,
@physname = N’D:\MSSQL\DATA\PubsDB.mdf’
GO
[/cc]

Thank you soooo much! It worked perfectly.
👿