Another Way which worked for me is:
After dettaching before you attach
-> go to the .mdf file -> right click & select properties on the file -> security tab -> Check Group or usernames:
for your name\account (optional) and for "NT SERVICE\MSSQLSERVER"(NB)
List item
-> if not there than click on edit button -> click on add button
and enter\search NT SERVICE\MSSQLSERVER
-> click on OK -> give full rights -> apply then ok
then ok again do this for .ldf file too.
then attach