2009-11-25 87 views
1

我禁用了SQL 2005數據庫上的日誌傳送,並刪除了輔助服務器上的日誌傳送數據庫。但是,我無法通過T-SQL(sp_delete_log_shipping_primary_secondary,sp_delete_job)或使用輔助服務器上的管理工作室來刪除LSRestore_DB___作業。它只是不會去。查詢繼續執行好7個小時。 嘗試禁用,仍然不刪除。也重啓了服務器。也試過了任何人都可以幫我刪除這個SQL作業嗎?無法刪除SQL作業

回答

0

試過設置允許編輯系統表,並直接進入保存作業信息的系統表,並嘗試從那裏刪除行?

確保是額外小心這樣做,不建議,但有時直接編輯到系統表需要完成。

1

還有一篇好文章Can’t Delete Jobs。本文作者提供了一個腳本來解決這個問題,做的很好!

`CREATE PROC dbo.DropJob 
@JobName AS VARCHAR(200) = NULL 
AS 
DECLARE @msg AS VARCHAR(500); 

IF @JobName IS NULL 
BEGIN 
SET @msg = N'A job name must be supplied for parameter @JobName.'; 
RAISERROR(@msg,16,1); 
RETURN; 
END 
IF EXISTS (
SELECT subplan_id FROM msdb.dbo.sysmaintplan_log WHERE subplan_id IN 
(SELECT subplan_id FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN 
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName))) 
BEGIN 
DELETE FROM msdb.dbo.sysmaintplan_log WHERE subplan_id IN 
(SELECT subplan_id FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN 
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName)); 

DELETE FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN 
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName); 

EXEC msdb.dbo.sp_delete_job @[email protected], @delete_unused_schedule=1; 
END 
ELSE IF EXISTS (
SELECT subplan_id FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN 
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName)) 
BEGIN 
DELETE FROM msdb.dbo.sysmaintplan_subplans WHERE job_id IN 
(SELECT job_id FROM msdb.dbo.sysjobs_view WHERE name = @JobName); 

EXEC msdb.dbo.sp_delete_job @[email protected], @delete_unused_schedule=1; 
END 
ELSE 
BEGIN 
EXEC msdb.dbo.sp_delete_job @[email protected], @delete_unused_schedule=1; 
END 
GO` 

現在您可以使用以下命令調用SP;

`USE [msdb]; 
EXEC dbo.DropJob @JobName = N'Shrink_AWP_Databases.Subplan_1';`