When you try to attach .MDF file with out a log file to a SQL Server you will get error message that say An error occurred when attaching the database(s). To solve this problem you could just click on the Log file then remove it. Click OK. If you get the same error again click on the three dots on Current File Path column next to mdf file then select the file again and click ok.
Case 2:
The other case to watch out is make sure the account you are using to attach has enough privilege on the folder that holds the mdf file.
I will demonstrate that with Adventureworks.mdf in my download folder
Then let us give the full path and file name of the mdf
Now let us remove the log file as we discussed and click on OK
Then I get the same error again
To solve this you could copy the mdf file to the defaut folder where your service account has access such as C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER\MSSQL\DATA
Or if you have to use your current folder for example if we want to attach Adventureworks.mdf from Downloads folder then give our service account a full access to the folder
To do that right click on the folder then select properties. In the properties dialog click on Security tab and click on Edit…
Then click on the Add… button then enter your service account name on the Enter the object name to select box. Since this is my DEV machine and I am the only one who will be using it I will just give Every User a full access by using Everyone.
Then click on the Full Access check box
Now if we try to attach to file again it will work