Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSrepl_drop_expired_sub_cleanup_job

  No additional text.


Syntax

CREATE PROCEDURE sys.sp_MSrepl_drop_expired_sub_cleanup_job
(
	@publisher sysname = NULL
)
AS
BEGIN
	DECLARE @retcode       int,
			@agentname     sysname,
			@alert_name    sysname,
			@alert_id      int,
			@command	   nvarchar(max),
			@category_name sysname

	SET @retcode = 0

    -- Get expired subscription cleanup agent name
    set @agentname = formatmessage(20569) +
    				 CASE
    				 	WHEN @publisher IS NOT NULL THEN N' ' + QUOTENAME(UPPER(@publisher))
    				 	ELSE N''
    				 END

	-- Drop expired subscription cleanup job (if it exists)
    IF EXISTS
	(
		SELECT	*
		FROM	msdb.dbo.sysjobs_view
		WHERE	name = @agentname COLLATE DATABASE_DEFAULT
		  AND	UPPER(originating_server) = UPPER(CONVERT(sysname, SERVERPROPERTY('ServerName')))
          AND	master_server = 0
	)
	AND
	(
		-- Check database state only when non-HREPL
		@publisher IS NOT NULL OR
		NOT EXISTS
		(
			SELECT	name
			FROM	master.dbo.sysdatabases
			WHERE	(category & 4 = 4)
			   OR	(category & 1 = 1)
		)
	)
	BEGIN
        EXEC @retcode = sys.sp_MSdrop_repl_job	@job_name = @agentname

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
            RETURN (1)
		END
    END


	-- Set the alert id
    SET	@alert_id = 14157

	-- Drop expired subscription alert (if it exists) and only
	-- if no other published database or publisher
    IF EXISTS
    (
    	SELECT	*
    	FROM	msdb.dbo.sysalerts
    	WHERE	message_id = @alert_id
    )
	AND NOT EXISTS
	(
		SELECT	name
		FROM	master.dbo.sysdatabases
		WHERE	(category & 4 = 4)
		   OR	(category & 1 = 1)
	)
    BEGIN
    	-- Special check - drop the alerts if no more HREPL publishers as well
    	IF (OBJECT_ID('msdb.dbo.MSdistpublishers', 'U') IS NOT NULL)
		BEGIN
			IF EXISTS
			(
				SELECT	name
				FROM	msdb.dbo.MSdistpublishers
				WHERE	publisher_type != N'MSSQLSERVER'
			)
			BEGIN
				RETURN (0)
			END
		END

        SELECT	@alert_name = name
        FROM	msdb.dbo.sysalerts
        WHERE	message_id = @alert_id

        EXEC @retcode = msdb.dbo.sp_delete_alert @alert_name

        IF (@@ERROR != 0 OR @retcode != 0)
        BEGIN
            RETURN (1)
        END
    END

    RETURN @retcode
END

 
Last revision 2008RTM
See also

  sp_adddistributor (Procedure)
sp_dropdistpublisher (Procedure)
sp_dropdistributor (Procedure)
sp_replicationdboption (Procedure)
       



News

  Query a named instance
Sybase+ASE+silent+install
SQL 2008 R2
Deprecated procedures in SQL2008
Reporting Services item-level role definitions
Create all your missing indexes
Converting datetime field
Start MSSQL Server Profiler at time
Replicating MSSQL Server views
Exploring Microsoft Sharepoint
The OLE DB provider "SQLNCLI10" for linked server indicates.
Mobile solar charger
Oracle to SQL Server replication
Cannot insert the value NULL into column
Undocumented Microsoft SQL Server 2008
VMware
Zoekmachine optimalisatie
SQL Servers hidden objects
FckEditor
Flash in Ajax
De hype die AJAX heet
Barcode scannen
MySQL; Gratis, makkelijk en snel!
PHP
sIFR; de combinatie tussen HTML en Flash