Sunday 31 March 2013

Unable to shrink database log file ( DBCC shrinkfile gives error)

Sometimes when trying to shrink the database log file for Ms SQl Database using DBCC SHRINKFILE ('database-name_Log', 1), which is the name for log file. It gives the following error :

"Could not locate file  xxx_Log for database  in sys.database_files. The file either does not exist, or was dropped. "

Solution :

The file name should be the logical file name and not the physical file name. Look in the Database properties, on the Files tab for the Logical Name of the file you are trying to shrink, and use that name.

Alternately, you can run the following query in the respective database from Ms Sql Managment Studio to get the logical name

SELECT df.name FROM sys.database_files AS df WHERE df.type_desc = 'log'

No comments:

Post a Comment