Monday, May 14, 2018

Error trying to attach a SQL database: CREATE FILE encountered operating system error 5(failed to retrieve text for this error. Reason: 15105)

If you are trying to attach a database using SQL management studio and you get the next 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

It is because you are not running management studio as an administrator and the account you are using doesn't have the rights to open the database file.

To solve this problem, right click on the SQL management studio shortcut and select:
Run as Administrator

That will let you attach the database.

SQL database stuck going offline

If you are trying to take a database offline and it got stuck, looks like it is not accessible anymore, but it’s not quite offline, you need to kill all the processes related with that Database.

With the next command, see all the processes running and look for the ones related with the database:

EXEC sp_who2

Get each SPID with the DBName database you want to take offline, the use the next command to kill each process

KILL <SPID>

This should solve your problem.