[sql] CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105)

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?

This question is related to sql sql-server-2008 sql-server-express

The answer is


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.


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


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


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!


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


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'

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..


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.


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...


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

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.


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".


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

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.


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.


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


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


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


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.


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


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.


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;

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


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.


Examples related to sql

Passing multiple values for same variable in stored procedure SQL permissions for roles Generic XSLT Search and Replace template Access And/Or exclusions Pyspark: Filter dataframe based on multiple conditions Subtracting 1 day from a timestamp date PYODBC--Data source name not found and no default driver specified select rows in sql with latest date for each ID repeated multiple times ALTER TABLE DROP COLUMN failed because one or more objects access this column Create Local SQL Server database

Examples related to sql-server-2008

Violation of PRIMARY KEY constraint. Cannot insert duplicate key in object How to Use Multiple Columns in Partition By And Ensure No Duplicate Row is Returned SQL Server : How to test if a string has only digit characters Conversion of a varchar data type to a datetime data type resulted in an out-of-range value in SQL query Get last 30 day records from today date in SQL Server How to subtract 30 days from the current date using SQL Server Calculate time difference in minutes in SQL Server SQL Connection Error: System.Data.SqlClient.SqlException (0x80131904) SQL Server Service not available in service list after installation of SQL Server Management Studio How to delete large data of table in SQL without log?

Examples related to sql-server-express

SQL ServerĀ® 2016, 2017 and 2019 Express full download SQL Server after update trigger How to create a connection string in asp.net c# SQL Insert Query Using C# ASP.NET 4.5 has not been registered on the Web server Connecting to SQL Server Express - What is my server name? CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105) Enable tcp\ip remote connections to sql server express already installed database with code or script(query) Default instance name of SQL Server Express How do I fix a "Performance counter registry hive consistency" when installing SQL Server R2 Express?