Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

maintenance plan is NOT working

Posted on 2008-06-16
7
Medium Priority
?
684 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
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!

 

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 70

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

705 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