Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 685
  • Last Modified:

maintenance plan is NOT working

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
moodi_ali
Asked:
moodi_ali
  • 4
  • 2
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
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
 
moodi_aliAuthor Commented:
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
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>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
Industry Leaders: 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!

 
moodi_aliAuthor Commented:
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
 
Scott PletcherSenior DBACommented:
You should have an initial database setting on the task somewhere.  Change it from master to your db name.
0
 
moodi_aliAuthor Commented:
ScottPletcher: ,this option is available in JOBS ,not in maintenance plans ,check SSMS
0
 
moodi_aliAuthor Commented:
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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

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