Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 516
GibboK Avatar asked Jun 24 '12 15:06

GibboK


People also ask

What is operating system error 5?

System error 5 is an error access denied code which means that your access is denied because you don't have the required privileges to run a certain command. For example, when you try to run a command which is supposed to stop the print spooler, you will get an error message.

Could not open connection to SQL Server error 5 access is denied?

The problem is due to lack of permissions for SQL Server to access the mdf & ldf files. All these procedures will work : you can directly change the MSSQLSERVER service startup user account, with the user account who have better privileges on the files. Then try to attach the database.

What is NT service Mssqlserver?

New pseudo-account is created called “NT SERVICE⧹MSSQLSERVER” or “NT SERVICE⧹SQLSERVERAGENT,” basically the account is “NT SERVICE” for the domain name followed by the name of the service. This allows each service to function within its own security context and not have access to the resource of another service.


2 Answers

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

like image 73
GibboK Avatar answered Oct 05 '22 19:10

GibboK


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

like image 44
user2029904 Avatar answered Oct 05 '22 18:10

user2029904