Monday, February 22, 2016

Msg 8985, Level 16, State 1, Line 2 Could not locate file '' for database '' in sys.database_files. The file either does not exist, or was dropped.

This error raised when i want to shrink log file, the solution for this just rename the logical file in SQL management studio, i am using SQL 2012 version :

In my case this error caused by, when restore backup file we choose another name for db, unfortunately the logical name is still using previous name.

So the solution is :

Please following this step :
  1. Open management studio
  2. Right click the database  > Properties
  3. Pics  
  4. Click files and change the logical the with the correct one, for me is 'MSDBAX' replace with 'MSTestAX'
  5. Pics
  6. Click ok
  7. Now you can run the script for truncate the log file, like sample below
USE [MSTestAX]
GO
ALTER DATABASE [MSTestAX] SET RECOVERY SIMPLE WITH NO_WAIT
DBCC SHRINKFILE(MSTestAX_log, 1)
ALTER DATABASE [MSTestAX] SET RECOVERY FULL WITH NO_WAIT
GO

 
8. Finish
READ MORE - Msg 8985, Level 16, State 1, Line 2 Could not locate file '' for database '' in sys.database_files. The file either does not exist, or was dropped.