• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 41
  • Last Modified:

DBCC Shrink File issues unable to locate file.

Hi EE,

I am having troubles with shrinking a database log file when I run the following command:

USE master
GO
ALTER DATABASE RiskMan_PRD_TST SET RECOVERY SIMPLE WITH NO_WAIT
GO
DBCC SHRINKFILE ('RiskMan_PRD_TST_log', 100)
GO
ALTER DATABASE RiskMan_PRD_TST SET RECOVERY FULL WITH NO_WAIT
GO

Open in new window


Could not locate file 'RiskMan_PRD_TST_log' for database 'master' in sys.database_files. The file either does not exist or was dropped.

The only issue is that these are what is listed when I run the following command, see screenshot.

I am doing some wrong how do I proceed?

Any assistance is welcome.
DB-Testing.PNG
0
Zack
Asked:
Zack
1 Solution
 
Nitin SontakkeDeveloperCommented:
At beginning of the script you have mentioned 'master', instead it should be the database name, so try as follows:

USE master
GO
ALTER DATABASE RiskMan_PRD_TST SET RECOVERY SIMPLE WITH NO_WAIT
GO
USE RiskMan_PRD_TST 
GO
DBCC SHRINKFILE ('RiskMan_PRD_TST_log', 100)
GO
ALTER DATABASE RiskMan_PRD_TST SET RECOVERY FULL WITH NO_WAIT
GO

Open in new window


Because error message indicates it is looking for the database file in master database.
0
 
Nitin SontakkeDeveloperCommented:
0
 
ZackGeneral IT Goto GuyAuthor Commented:
Cheers Nitin, smack for me I should have seen that one :)
0
 
Mark WillsTopic AdvisorCommented:
Yep, you need to be in the correct DB.

https://technet.microsoft.com/en-us/library/ms189493(v=sql.105).aspx

Or do it in SSMS, right click on the database name (left hand side in object explorer), Tasks => Shrink = > Files and choose the transaction log from the filename dropdown. Should also select the option to reorg - but will take longer - so that's your call.
0
 
Bharat BhushanSolution ManagerCommented:
Yesh, I agree with Mark.. you need to be in the correct DB
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now