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
ZackGeneral IT Goto GuyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.