C# ASP.NET SQL SERVER

CREATE FILE encountered operating system error 5 Access is denied

I have an MSSQL 2008 R2 installation and was trying to attach a DB from a non-R2 installation using SQL Server Management Studio (SSMS) and I was getting the following error:

CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDataBase.mdf'. (Microsoft SQL Server, Error: 5123)

Found plenty of Google results pointing me to suggestions about SQL Server 2000 and 2005 with instructions on how to add user permissions and which user account needed to be added.

Turned out that all I needed to do was to run SSMS as an administrator and the attach worked.

» Similar Posts

  1. Google Chrome Installer Error 1625
  2. ASP.NET MVC Preview 3 to Preview 4
  3. Hosts file locked (read-only) on Server 2008

» Trackbacks & Pingbacks

    No trackbacks yet.
Trackback link for this post:
http://guyellisrocks.com/trackback.ashx?id=258

» Comments

  1. Udo avatar

    I have resolved the problem with the following steps:

    1. Set OS permission on the .mdf file to full permission for 'Everyone'.

    2. Attach the database.

    Udo — July 28, 2010 9:01 AM
  2. Plamen Kasabov avatar

    The problem on my side was caused by changing the Operating system to Windows 7. Using runas command solved it. Thanks!

    Plamen Kasabov — November 4, 2010 12:04 PM
  3. BimBim avatar

    Hi Udo! Thanks.

    (Set OS permission on the .mdf file to full permission for 'Everyone')

    BimBim — November 7, 2010 10:36 PM
  4. David avatar

    confirmed as a solution.

    David — January 5, 2011 3:28 PM
  5. Srikanth Guduru avatar

    Yes Confirmed as Solution

    Srikanth Guduru — May 16, 2011 2:30 AM
  6. yogi avatar

    great , its working

    yogi — June 2, 2011 9:07 AM
  7. pjr avatar

    Thanks.

    pjr — June 26, 2011 7:43 PM
  8. bushan avatar

    great solution

    bushan — June 28, 2011 12:24 PM
  9. Arif Riyanto avatar

    Haaaa,, it's works.. thanks

    Arif Riyanto — August 13, 2011 1:49 AM
  10. Dharmesh Puthran avatar

    Yeah..I too confirm as solution...

    Thanks

    Dharmesh Puthran — September 20, 2011 5:40 AM
  11. Astrogator avatar

    Confirmed as well. However, a puzzle that i can't answer: had 2 DBs to re-attach, 1st one worked like a charm, on 2nd got that same error. DBs in question have the same origin (SourceGear Vault) - [sgmaster] and [sgvault], and aren't any different in permissions or such. Also noticed that in the error message the .mdf file is specified along with "CreateFile failed" - why is SMSS (or SQL) trying to create a file which already exists!? If anyone has a clue, i'd appreciate it!

    Astrogator — December 21, 2011 2:45 PM
  12. vbanuelos avatar

    Thanks, that definitely was the fix for my team!

    vbanuelos — January 11, 2012 5:21 PM
  13. Stuart avatar

    at first I was a bit wary of the domain name, but fair play, this sorted my problems (and made some support guy at DoubleTake's day a lot easier), so there is indeed some rocking!

    Tommy Vance would be impressed.

    Stuart — January 18, 2012 5:23 AM
  14. Part Time dba avatar

    Open QL Server Management Studio by right clicking and saying "Run as Administrator".

    From: social.msdn.microsoft.com/.../16071cf8-b9ef-4

    Part Time dba — January 24, 2012 6:11 AM
  15. Rufus avatar

    Excellent... It works! Confirmed!!!!!

    Rufus — April 4, 2012 3:57 AM
  16. Eric avatar

    Thanks a bunch! I took me a good 8 hours to track down this error.

    Eric — May 18, 2012 1:29 PM

» Leave a Comment