An error occurred when attaching the database(s). Click the hyperlink in the Message column for details.
While attaching .mdf and .ldf database files in SQL server management studio, it throws error attached image – 1
Image – 1
It seems permission issue for which it gives this error while attaching the .mdf and .ldf file. so to make it work, we need to give permission to the folder containing the database (.mdf, .ldf). else directly to the database files.
As shown in Image – 2. it does not have full control for which it throws error while attaching database.
Image – 2
Now I have given Full Control access to the Users for those .mdf and .ldf file as shown in Image – 3
Image – 3
Now do the same process to attach the .mdf file by right clicking on database and locate the .mdf file to restore.
This time database will get attached successfully without giving any error.
Another way you to overcome this error
while attaching the .mdf file is to stop the SQL Server service first
To START and STOP SQL Server Service Go to run type services.msc once that page opens search for SQL Server Service and STOP it from the left panel. Same process to START the SQL Server Service
and then put the .mdf and .ldf inside Data folder where SQL Server was installed and then restart the SQL Server service, then attach the .mdf file. it wont give permission error.
You might also like:
How to truncate a SQL Server Data file
How to Backup a Database using SQL Management Studio
How to Restore Database using SQL Management Studio
Failed to connect to MySQL at with user root cannot connect to MySQL server on (10060)