Solved

maintenance plan is NOT working

Posted on 2008-06-16
7
680 Views
Last Modified: 2008-06-29
Dear Experts:
I create a new maintenance plan in SQL 2005 to shrink a LOG file ,i place "execute SQL command" using the maintenance plan designer ,that has the following code:

USE [NEW_HEALTH]
GO
DBCC SHRINKFILE  (NEW_HEALTH_log_1 ,1)
GO

the code executes perfectly using the query window ,BUT when executed through the maintenance plan it displays the following error:

Executing the query "DBCC SHRINKFILE  (NEW_HEALTH_log_1 ,1)
" failed with the following error: "Could not locate file 'NEW_HEALTH_log_1' for database 'master' in sys.database_files. The file either does not exist, or was dropped. ". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.

why is it going to master instead of MY DATABASE NEW_HEALTH?
0
Comment
Question by:moodi_ali
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21800256
first of all, I would not create a maintenance plan task for a simple sql job, but plain sql agent job with just that sql and setting the correct database.

however, if you plan to schedule a transaction log shrink, you have something wrong anyhow:
* if your database is in full recovery mode, and you have regular transaction log backups
   -> don't shrink the log file all the time, you just waste IO, as the file will grow again.
   note: once the log is backed up with BACKUP LOG ... statement, it will reuse it's file space, and not grow endlessy

* if your database is in simple recovery mode, then do nothing
   -> don't shrink the log file all the time, you just waste IO, as the file will grow again.
   note: once the a transaction is committed, the used log file space can be reused, the file will not grow endlessy

remark:
there is only 1 "problem": that is a transaction staying open and not doing the commit/rollback. that will keep the log file from reusing the space
however, in that situation, only to end the transaction will solve that problem.

0
 

Author Comment

by:moodi_ali
ID: 21800309
fine i think i need to give you the full picture:
the shrink LOG is part of a huge maintenance plan that includes FULL backup ,reindex ,re organize ,shrink all database on server.
since rebuilding all indexes is making the LOG go very HUGE ,what i do is ,make the recovery mode of the DB Simple and return it to full after i finish rebuildling indexes ,however ,the LOG is still HUGE after maintenance plan completes.
to work arround this ,i added a new step in the maintenance plan to shrink the LOG file (that is supposed to return the free space to OS) ,BUT this step is failing as i metniotned.

how can i reslove that error ,i am curious to know ,in case i wanted to execute another step in the future ,WHY is the USE statement being omited?


0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 21800345
>since rebuilding all indexes is making the LOG go very HUGE
which is ONE of the main reasons why you should NOT rebuild all the indexes all the time.
recomputing the stats is usually enough...

anyhow, still the same reason applies: if you shrink the log file, the next maintenance plan will waste time to grow the log file again...

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:moodi_ali
ID: 21800861
Angell ,since this is happening duirng mid night ,then i dont really care if takes long time or not ,the LOG is growing to a very big size and i am afraid that it might get corrupted or swallow the whole drive.

i need to rebuild indexes at least once a week.

could you please tell me whats wrong with the code i sent? ,this is a serious problem if i can NOT use "USE statement" even for other commands.
you can create a seperate maintenance plan on ur laptop that has the above mentioned code and run it.
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 21806182
You should have an initial database setting on the task somewhere.  Change it from master to your db name.
0
 

Author Comment

by:moodi_ali
ID: 21810123
ScottPletcher: ,this option is available in JOBS ,not in maintenance plans ,check SSMS
0
 

Accepted Solution

by:
moodi_ali earned 0 total points
ID: 21836907
this is the solution :
Remove the GO from the code ,it looks like SQL switches back to master after any USE statements :
code that worked:

USE [NEW_HEALTH]
DBCC SHRINKFILE  (NEW_HEALTH_log_1 ,1)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how the fundamental information of how to create a table.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question