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.
I have resolved the problem with the following steps:
ReplyDelete1. Set OS permission on the .mdf file to full permission for 'Everyone'.
2. Attach the database.
The problem on my side was caused by changing the Operating system to Windows 7. Using runas command solved it. Thanks!
ReplyDeleteHi Udo! Thanks.
ReplyDelete(Set OS permission on the .mdf file to full permission for 'Everyone')
confirmed as a solution.
ReplyDeleteYes Confirmed as Solution
ReplyDeletegreat , its working
ReplyDeletegreat solution
ReplyDeleteHaaaa,, it's works.. thanks
ReplyDeleteYeah..I too confirm as solution...
ReplyDeleteThanks
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!
ReplyDeleteThanks, that definitely was the fix for my team!
ReplyDeleteat 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!
ReplyDeleteTommy Vance would be impressed.
Open QL Server Management Studio by right clicking and saying "Run as Administrator".
ReplyDeleteFrom: social.msdn.microsoft.com/.../16071cf8-b9ef-4
Excellent... It works! Confirmed!!!!!
ReplyDeleteThanks a bunch! I took me a good 8 hours to track down this error.
ReplyDeleteLogin as windows
ReplyDeleteHow to set OS permission on an mdf file?
ReplyDeleteRight click on the Management studio then click on
ReplyDeleteRun as Administrator then attach the database.
Thanks!
Start SQL Server manager as Administrator (right-click on the program, choose "Start as administrator"): problem solved!
ReplyDeletePerfect ;)
ReplyDeleteThanks
What is the .mdf file? The database?
ReplyDeleteI had this issue and all the solutions online was misleading. I had the solution here. Thanks you shared it too. dotnet-programming-solutions.blogspot.com/.../attach-database
ReplyDeleteStarting as administrator and set OS permission on the .mdf file to full permission for 'Everyone' is an excellent answer!!... it works terrific!... thanks a lot..
ReplyDeleteSolved my issue as well!
ReplyDeleteIn case there is a transaction log you need to change the security for this file, too!
The reason for this issue in my case was that I detached the file with another user than the user I wanted to use to reattach.
In my case, this error was occurring when trying to Create a new database.
ReplyDeleteI was already running SSMS as an administrator, so that was not the solution for my problem.
Turned out I had to modify ACL on the Windows folder where the physical file for the database was to be created. I granted the SQL user account permissions to create files in my new database target folder.
Hi Udo,
ReplyDeleteyour solution is working properly,
thanks in advance
Thanks Manish!!! Solution worked like a charm!!!
ReplyDeleteOther solution. Change the account for run SQL Services.
ReplyDeleteHi All,
ReplyDeleteI used Run as admin of SSMS. it worked for me also.
Thanks all,
Praveen Sagar Velpula
I have a problem is there any SqlServer Expert to solve it when i attached the database in sqlserver then it give the following problems and give the following messags
ReplyDeleteCREATE FILE encountered operating system error 32(The process cannot access the file because it is being used by another process.) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\WPS.mdf'. (.Net SqlClient Data Provider)
Are you running SSMS as an administrator? Right click and select "Run as Administrator."
DeleteThis comment has been removed by the author.
DeleteDear all hello to every one
ReplyDeletei want to could attached the database in sqlserver in Network environment then it give the following message
is there any body here to help me thanks
CREATE FILE encountered operating system error 32(The process cannot access the file because it is being used by another process.) while attempting to open or create the physical file 'C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\WPS.mdf'. (Microsoft SQL Server, Error: 5123)
Yes but the folder which the mdf and ldf is exists this folder is read only when i remove it is again check by default read only
ReplyDelete