Quantcast
Channel: SQL Server Database Engine forum
Viewing all articles
Browse latest Browse all 12963

DBCC SHRINKFILE command in maintenance plan job works manually, but not on schedule

$
0
0

In an attempt to release log file empty whitespace, we've added the following t-sql statement task as part of a weekly maintenance plan job:

EXEC master.sys.sp_MSforeachdb
'DECLARE @ln varchar(max)
SET @ln=(SELECT name FROM [?].dbo.sysfiles WHERE fileid=2)
USE [?]

BEGIN TRY
DBCC SHRINKFILE (@ln);
END TRY

BEGIN CATCH
END CATCH'

If I 'Start job at step' that single job manually, it seems to run fine and release quite a bit of unused whitespace.  We have another domain user that runs the agent service, which has full rights to the log files themselves as well as sysadmin server role and seemingly random user mappings.  When checking the job history, it shows that the job completed successfully, but when we view the history of the size of the drive, there is no change at that time.  I'm wondering if anyone has any idea about what might be happening here.

Thanks
jt


Viewing all articles
Browse latest Browse all 12963

Trending Articles