Thursday, June 25, 2015

Unable to open physical file - Operating system error 5: 5

Simply open "SQL Server Configuration Manager"
In side "SQL Server Configuration Manager" in the right-side, right-click on the service name which you are using currently
Select Properties
Now you can do one of the followings:
     - Change the log on service account to an account with appropriate privileges.
     OR
     - Give the selected log on service account an appropriate privileges on your file system (for example: D:\SQLDatabase\)


https://social.msdn.microsoft.com/Forums/sqlserver/en-US/9e563890-e35f-4524-82b9-3cca08fec5ed/unable-to-open-physical-file-operating-system-error-5-5error-not-found-microsoft-sql-server?forum=sqldatabaseengine

My quick fix was to:
- right-click on the file in Windows Explorer, select Properties
- select the Security tab
- Click Advanced
- Click Change Permission
- Uncheck "Include inheritable permissions...", a window will open
- Click Remove (removes all permissions), the window will close
- Click Add
- Enter your login name and click OK, the permission window will open
- Check Full Control - Allow
- Click OK, OK, OK, OK

Do this for the MDF and LDF files.

I was then able to attach the database.

Cheers,

Solution To The MSSQL Server “Suspect”

EXEC sp_resetstatus ‘DATABASE_NAME’;
ALTER DATABASE DATABASE_NAME SET EMERGENCY
DBCC checkdb(‘DATABASE_NAME’)
ALTER DATABASE DATABASE_NAME SET SINGLE_USER WITH ROLLBACK IMMEDIATE
DBCC CheckDB (‘DATABASE_NAME’, REPAIR_ALLOW_DATA_LOSS)
ALTER DATABASE DATABASE_NAME SET MULTI_USER