Solved

maintenance plan is NOT working

Posted on 2008-06-16
7
671 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 142

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 142

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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:ScottPletcher
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

708 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now