Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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 am getting an error trying to attach a database whose files were previously encrypted via EFS. The actuall error message is

Msg 5120, Level 16, State 101, Line 9
Unable to open the physical file "C:\test.mdf". Operating system error 5: "5(Access is denied.)".

If I decrypt the files, then I successfully can attach the database. I am using the same domain user who did the encryption. Any ideas?

share|improve this question

migrated from Oct 15 '12 at 3:21

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

Belongs on server fault. – Richard Aug 26 '09 at 8:35

For the benefit of the community, I found out the cause of this issue as follows: 1. Detaching/Attaching the database uses the currently logged on user. 2. Encrypting/Decrypting db files uses the sql server service account 3. So if the currently logged on user is a different account to that of the sql server service, clearly there will be an error trying to attach the database because the files were encrypted via account (EFS works like that) 4. To resolve, use the same account to encrypt and attach

share|improve this answer

I am using the same domain user who did the encryption.

The SQL Server Service account will need to be able to access and decrypt the file as well (all file operations by the service are done under the account it runs at, whatever account is being used by clients).

share|improve this answer

Hi Jangwenyi check again ,make sure that the startup account of sql server is the same as the account that encrypted the db. Bye.

share|improve this answer

Your Answer


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

Not the answer you're looking for? Browse other questions tagged or ask your own question.