CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105)
Asked Answered
L

27

75

I have a database file .mdf from MS SQL EXPRESS in folder:

C:\Program Files\Microsoft SQL Server\MSSQL10.SQLEXPRESS\MSSQL\DATA

I would like to attach it to MS 2008 R2 (MSSQL10_50.MSSQLSERVER) but using Server Management Studio I receive the following error:

CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105) while attempting to open or create the physical file

Do you have any idea how to solve it?

Ludwog answered 24/6, 2012 at 15:7 Comment(3)
Is it possible the mdf is already attached to an instance of SQL Server, or it is open in a Visual Studio project or something along those lines? Have you tried making a copy of the file and attaching that? Where did the MDF file come from? Is it possible it wasn't detached cleanly from its original source?Alecto
Is SQL Server running as administrator? See CREATE FILE encountered operating system error 5 Access is deniedGurglet
Thanks guys for your comments, I was able to solve the issue running as ADMINISTRATOR thanks!Ludwog
L
146

I was able to solve the problem running MS SQL Management Studio as ADMINISTRATOR.

Ludwog answered 24/6, 2012 at 15:11 Comment(3)
The response by stackoverflow.com/users/2029904/user2029904 is much less aggressive and resolves the underlying problem - insufficient access by the instance account to the database file.Silvio
@Ludwog what if database create with EF:Code First? i change my model and when i try to run program this error apear.i run VS as administrator but nothing changeBakery
Fixing "insufficient access by the instance account to the database file" didn't work for me, only running as Administrator worked. Why doesn't one Microsoft programmer fix this once and save us all this unnecessary pain?Punish
W
52

It's a Windows permissions issue. If you connected to your server using Windows Authentication then that Windows user needs permissions to the file. If you connected to your server using SQL Server authentication then the SQL Server instance account (MSSQL$, e.g. MSSQL$SQLEXPRESS) needs permissions to the file. The other solutions suggesting logging in as an administrator essentially accomplish the same thing (with a bit of a sledgehammer :).

If the database file is in your SQL Server's data folder then it should have inherited the user rights for the SQL Server account from that folder so the SQL Server authentication should have worked. I would recommend fixing the SQL Server instance's account's rights for that folder. If the data file is somewhere else and the SQL Server account does not have permissions then you will likely encounter other problems later. Again, the better solution is to fix the SS account rights. Unless you are always going to log in as administrator...

Wrinkle answered 31/1, 2013 at 16:56 Comment(5)
Edit the Security properties for the data folder to include full control for the user running SQL Management Studio.Dmz
The instance account attempts to open the data and log files with a Write DAC permission. This is available if the <Machine>\Users account has full permission to the files. When the Test connection succeeds, these permissions are overwritten to specific SQL Server values, erasing the temporary settings.Silvio
I'd really like to use this option instead of running SQL Server Management Studio as an administrator. I've assigned both likely looking users full control over my directory / files but I'm still getting the same error. How do I know which is the correct user to give authorisation to these files?Disable
Run As Administrator does not work for me. When I check, SQL Server in services, it was running under Network Service account. I give Network Service rights on that folder, and create database is a success :)Dissonant
This answer directed me to my solution: Make sure the identity that SQL Server Service is running with (like, "NT Service\MSSQLSERVER"), has access to the DATA folder.Agape
N
8

Start->Run->services.msc->scroll through the list of services until you find SQL Server->right-click->properties->Log On tab:

Then choose Local System Account and check the Allow service to interact with desktop checkbox.

Restart the service.

Services

Negris answered 27/2, 2019 at 14:12 Comment(0)
C
4

Right Click on File mdf and ldf properties -> security ->full permission

Coleridge answered 20/1, 2015 at 18:51 Comment(0)
S
4

Giving admin rights or full control to my database install location solved my problem

Syncopated answered 8/7, 2015 at 15:3 Comment(0)
R
3

I had the same problem. After several tries, I realized that connecting the sql server with windows authentication resolved the issue.

Ratiocinate answered 22/11, 2012 at 16:27 Comment(2)
This resolved the issue for me. Running SQL Server Management Studio as administrator did not solve it for me.Cloy
In contrast to me, I logged in using the SQL Server authentication with the "sa" account and it works.Gretchen
T
2

I was getting similar error.

CREATE FILE encountered operating system error **32**(failed to retrieve text for this error. Reason: 15105) while attempting to open or create the physical file

I used the following command to attach the database:

EXEC sp_attach_single_file_db @dbname = 'SPDB',
@physname = 'D:\SPDB.mdf'
Tyranny answered 1/6, 2013 at 20:30 Comment(0)
P
1

This same problem occurs when the owners of the file have been deleted. When this happens, if you go to the file's properties, you will see a SID rather than a user name. Take ownership of the file (giving yourself FULL CONTROL). Once that is done you can do whatever you need to do with the file.

I've had this work when logging in as the administrator didn't do the trick.

Porterhouse answered 30/11, 2012 at 15:0 Comment(0)
D
1

As other suggested running as administrator will help.

However this only if the windows user is actually an admisnitrator on the machine which sql server runs.

For example when using SSMS from a remote machine it will not help using "run as administartor" if the user is only a administrator on the machine runing SSMS but not on the machine running SQL Server.

Drysalter answered 9/5, 2013 at 19:39 Comment(0)
M
1

1.copy your --.MDF,--.LDF files to pate this location For 2008 server C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA 2.In sql server 2008 use ATTACH and select same location for add

Melamie answered 23/5, 2013 at 12:49 Comment(0)
B
1

I had this issue on Windows 2003 with SQL 2005. I had to take ownership of the files as my Windows user account and I got the database to attache that way.

You have to right click on the file, select Properties, click OK to get past the information screen, click the Advanced button, select your account from the listing of available accounts or groups, apply that change, and Click OK on the Properties screen. Once you have done all that you will be able to manage the file permissions.

I logged into SSMS with Windows Authentication and I was able to attach the database without error.

Cheers!

Barsky answered 4/1, 2014 at 13:19 Comment(0)
M
1

I also face same problem, but i run Sql server run as administrator so now i resolve the error.

Multidisciplinary answered 12/10, 2022 at 6:33 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Scuba
Z
0

If you are already running as an adminstrator, make sure the user you are using has the proper server roles.

  1. Login as sa (if you can)
  2. Expand the Security folder
  3. Expand the Logins Folder
  4. Right click on the user you would like to use
  5. Select Properties
  6. Select Server Roles
  7. Select all the server roles
  8. Click OK
  9. Restart SSMS
  10. Login with the modified user
Zulmazulu answered 24/4, 2013 at 15:14 Comment(0)
W
0

In my case I have got the error when trying to create a databae on a new drive. To overcome the problem I created a new folder in that drive and set the user properties Security to full control on it(It may be sufficient to set Modify ). Conclusion: SET the Drive/Folder Properties Security for users to "Modify".

Wavawave answered 13/5, 2014 at 4:45 Comment(0)
A
0

My solution was slightly more complicated. After verifying the user the service was running as, running MSSMS as local and domain administrator, and checking folder permissions, I was still getting this error. My solution?

Folder ownership was still maintained by local account.

Properties > Security > Advanced > Owner > (domain/local user/group SQL services are running as)

This resolved the issue for me.

Anet answered 15/7, 2014 at 19:22 Comment(0)
N
0

copy your --.MDF,--.LDF files to pate this location For 2008 server C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA 2.

In sql server 2008 use ATTACH and select same location for add

Natividadnativism answered 21/8, 2014 at 7:53 Comment(0)
B
0

Opening SSMS as Administrator and running as SQL Auth vs Windows Auth did not work.

What worked was to just change my filename to the same location where the LDF and MDF files are located.

alter database MyDB
add file ( name = N'FileStreamName', 
filename = N'D:\SQL Databases\FileStreamSpace' ) 
to filegroup DocumentFiles;
Bathilda answered 9/12, 2014 at 9:54 Comment(0)
L
0

Here are the steps:

  1. Right click on the .mdf and .ldf file.
  2. Then select properties.
  3. On the security -> advanced -> permission add the user which
Latecomer answered 25/8, 2015 at 6:22 Comment(0)
T
0

I got this error when restoring a database that was backed up on another server. After a long struggle this is what I did

  1. Enabled Instant File Initialization,

  2. Granted permissions (full control) on the folder to the service account and my own windows account,

  3. Restarted the SQL service. Database restored after that.

Timetable answered 1/12, 2015 at 15:7 Comment(0)
G
0

The key is "operating system error 5". Microsoft helpfully list the various error codes and values on their site

https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx

ERROR_ACCESS_DENIED 5 (0x5) Access is denied.

Gilding answered 20/1, 2016 at 21:27 Comment(1)
OP is asking how to solve it, not stating what he's already mentioned in more detail.Chorography
S
0

We faced this issue, when the windowsuser detaching the database and windowsuser attaching the database are different. When the windowsuser detaching the database, tried to attach it, it worked fine without issues.

Scalage answered 12/5, 2017 at 21:10 Comment(0)
S
0

I just decided to create the file in D: instead of C: and everything worked well. windows 7...10 have many issues regarding the sharing and authorization of files and folder..

Stereotypy answered 17/3, 2018 at 11:10 Comment(0)
L
0

In my case, Run as Administrator does not help. I solved the problem by changing the Build-in Account to Local System in Configuration Manager.

Ledet answered 3/11, 2018 at 9:20 Comment(1)
I don't see this option in my Visual Studio solutions's Configuration Manager. What do you mean?Asthmatic
B
0

Here is what happened in my case. I was asked to attach files for a database. I was given the file names as follows

  • devdb.mdf and devdb.ldf

I proceeded to attach the files and kept getting the files are in use by another process.

I ran a query against the system view select name, physical_name from sys.master_files; and saw that the exact file names were already in use by another database, thus each time I tried to attach the files, I kept getting the error the files are in use by another process(sql server)

Thus if you are getting such a message, then also query against the system view sys.master_files and see which database may already be using the same name files. Hereafter you will figure out what to do.

thanks.

Billingsley answered 11/12, 2018 at 21:33 Comment(0)
B
0

if you have mount points add the the SQL server service account to volume security accordingly

Bind answered 20/2, 2019 at 9:58 Comment(0)
L
0

If facing similar issue in SQL Server running on docker container, fix by granting appropriate permissions to volumes.

  1. Login to container as root user

    docker exec -it -u root <container id> bash

  2. Grant appropriate permissions to all volumes path e.g. /var/opt/sqlserver/data

    chmod 777 </var/opt/sqlserver/data>

Lazo answered 9/3, 2023 at 9:25 Comment(0)
D
-2

No need to do all this. Just right click on database files and add permission to everyone. That will work for sure.

Datum answered 13/3, 2014 at 18:49 Comment(2)
actually this worked for me, the other option to run Management studio as administrator did not help, but changing file permissions did the trick. And btw - the question was about ideas how to solve the problem - so IMO this is an answer (although not very polished)Schnur
Giving "Everyone" (effectively, this should be read as "every human in the world") permission to mess with your database is hardly a solution, though it may hide the real problem.Ostium

© 2022 - 2024 — McMap. All rights reserved.