Solved

maintenance plan is NOT working

Posted on 2008-06-16
7
676 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
  • 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
OSQL to execute sql command 26 24
SQL Availablity Groups Shared Path 2 16
Need help in debugging a UDF results 7 25
job schedule 8 19
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
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.
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.

860 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