Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I installed sql server 2008 on windows 7 then i create a Database! after 2 days, i reinstall the windows and isntall the sql server! now i am trying to attach my database file, bot i encounter to bellow error. i think that the files are like a attached file and i cant attach them. what is diffrence of an attached file and a not attached file? how can i to attach this file? Please Help Me.

Error Text:

TITLE: Microsoft SQL Server Management Studio

Attach database failed for Server 'AMIR-PC'. (Microsoft.SqlServer.Smo)

For help, click:


An exception occurred while executing a Transact-SQL statement or batch. (Microsoft.SqlServer.ConnectionInfo)

Unable to open the physical file "F:\Company.mdf". Operating system error 5: "5(Access is denied.)". (Microsoft SQL Server, Error: 5120)

For help, click:

share|improve this question

migrated from Jun 29 '12 at 14:59

This question came from our site for professional and enthusiast programmers.

Crossposted -… – squillman Jun 29 '12 at 15:12

I'm pretty sure the problem is that due to the uninstall/reinstall of SQL Server, the database engine no longer has permissions on the database files.

If you move the .mdf and .ldf files to the data folder that you specified on install, it should work for you. If you want to keep the files where they are, make sure the permissions are configured to allow appropriate access to the database engine service account group.

share|improve this answer
Ok.. Very Very GooooooooooooD! Thanks A Lot for your answer! I moved Th .mdf & .ldf databases File To "C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER2\MSSQL\DATA" Folder And I Successed to attach the Files! But i dont know how to change database engine permision To Attach the files without moving! How To Change Permision for allow access my database file? – user9772 Jun 30 '12 at 20:57
@Amir: See here:… – Jon Seigel Jul 1 '12 at 13:06

I had this issue and the solution was to Run SSMS as Administrator. I blogged about it here.

share|improve this answer
We don't appreciate multiple widespread answers like this. If you want to link to your blog, that's fine, but the answer should be substantive and should stand on its own. I'm removing duplicate posts because they aren't helpful as-is. – jcolebrand Oct 17 '12 at 15:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.