Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MScleanupdynamicsnapshotfolder

  No additional text.


Syntax

-- Name: sp_MScleanupdynamicsnapshotfolder

-- Description: This procedure is used to cleanup the specified dynamic
--              snapshot folder. It is designed to be called through the
--              distributor RPC link.

-- Parameters: @publisher                   sysname
            
--             @publisher_db                sysname
            
--             @publication                 sysname
            
--             @dynamic_filter_login        sysname
            
--             @dynamic_filter_hostname     sysname
            
--             @dynamic_snapshot_location   nvarchar(260)
      
--             @partition_id                int


-- Security: Public procedure invoked via RPC. db_owner check
  
-- Requires Certificate signature for catalog access
           

CREATE PROCEDURE sys.sp_MScleanupdynamicsnapshotfolder
         
(
    @publisher                   sysname,
    @publisher_db                sysname,
    @publication                 sysname,
    @dynamic_filter_login        sysname,
    @dynamic_filter_hostname     sysname,
    @dynamic_snapshot_location   nvarchar(260),
    @partition_id                int
)
as
begin
    set nocount on
           
    declare @retcode int
     
    declare @publisher_id int
    declare @publication_id int

    set @retcode = 0
         
    set @publisher_id = null
 
    set @publication_id = null

    set @dynamic_filter_login = coalesce(@dynamic_filter_login, N'')
    set @dynamic_filter_hostname = coalesce(@dynamic_filter_hostname, N'')

    
    -- security check
        
    -- only db_owner can execute this
    
    if (is_member('db_owner') != 1)
    begin
        raiserror(14260, 16, -1)
        return (1)
           
    end
    
    -- security check
        
    -- Has to be executed from distribution database
           
    
    if (sys.fn_MSrepl_isdistdb (db_name()) != 1)
    begin
        raiserror(21482, 16, -1, 'sp_MSdrop_publication', 'distribution')
        return (1)
           
    end

    -- Check if publisher is a defined as a distribution publisher in the current database
       
    exec @retcode = sys.sp_MSvalidate_distpublisher @publisher, @publisher_id OUTPUT
             
    if @retcode <> 0
         
    begin
        return(1)
            
    end

    -- Make sure publication exists
    select @publication_id = publication_id
        from dbo.MSpublications where publication = @publication and
        publisher_id = @publisher_id and publisher_db = @publisher_db
    if @publication_id is NULL
    begin
        -- We don't know whether or not it is a third party or not so we can not
        -- return error.
     
        -- raiserror(20026, 16, -1, @publication)
        -- return (1)
        
        return (0)
           
    end

    if @dynamic_snapshot_location is null or rtrim(@dynamic_snapshot_location) = N''
             
        return (0)
           

    declare @publication_snapshot_folder nvarchar(260)
         


    if substring(@dynamic_snapshot_location, len(@dynamic_snapshot_location), 1) <> N'\'
         
    begin
        set @dynamic_snapshot_location = @dynamic_snapshot_location + N'\'
    end

    exec @retcode = sys.sp_MSreplremoveuncdir @dynamic_snapshot_location
    if @retcode <> 0 or @@error <> 0
			return(1)
             

    -- If @partition_id is not null, attempt to do a pattern match and
    -- see if the given @dynamic_snapshot_location is generated by us
    -- for subscriber requested snapshot
    if @partition_id is not null
    begin
        declare @dynamic_snapshot_location_suffix nvarchar(4000)
        set @dynamic_snapshot_location_suffix = sys.fn_replcomposepublicationsnapshotfolder(@publisher, @publisher_db, @publication, 1) collate database_default + N'\' + sys.fn_replcomposepartitionfolder(@dynamic_filter_login, @dynamic_filter_hostname, @p
artition_id) collate database_default + N'\'
        if substring(@dynamic_snapshot_location, len(@dynamic_snapshot_location) - len(@dynamic_snapshot_location_suffix) + 1, len(@dynamic_snapshot_location_suffix)) = @dynamic_snapshot_location_suffix
        begin
            exec @retcode = sys.sp_MSdeletefoldercontents @dynamic_snapshot_location
             
            if @retcode <> 0 or @@error <> 0
		    	return(1)
             
        end

        if @dynamic_filter_hostname <> N'' and @dynamic_filter_login <> N''
        begin
            set @dynamic_snapshot_location_suffix = sys.fn_replcomposepublicationsnapshotfolder(@publisher, @publisher_db, @publication, 1) collate database_default + N'\' + sys.fn_replcomposepartitionfolder(@dynamic_filter_login, N'', @partition_id) coll
ate database_default + N'\'
  

            if substring(@dynamic_snapshot_location, len(@dynamic_snapshot_location) - len(@dynamic_snapshot_location_suffix) + 1, len(@dynamic_snapshot_location_suffix)) = @dynamic_snapshot_location_suffix
            begin
            
                exec @retcode = sys.sp_MSdeletefoldercontents @dynamic_snapshot_location
         
                if @retcode <> 0 or @@error <> 0
		    	    return(1)
         
            end


            set @dynamic_snapshot_location_suffix = sys.fn_replcomposepublicationsnapshotfolder(@publisher, @publisher_db, @publication, 1) collate database_default + N'\' + sys.fn_replcomposepartitionfolder(N'', @dynamic_filter_hostname, @partition_id) c
ollate database_default + N'\'
            if substring(@dynamic_snapshot_location, len(@dynamic_snapshot_location) - len(@dynamic_snapshot_location_suffix) + 1, len(@dynamic_snapshot_location_suffix)) = @dynamic_snapshot_location_suffix
            begin
            
                exec @retcode = sys.sp_MSdeletefoldercontents @dynamic_snapshot_location
         
                if @retcode <> 0 or @@error <> 0
		    	    return(1)
         
            end
        end
        set @dynamic_snapshot_location_suffix = sys.fn_replcomposepublicationsnapshotfolder(@publisher, @publisher_db, @publication, 1) collate database_default + N'\' + sys.fn_replcomposepartitionfolder(N'', N'', @partition_id) collate database_default +
 N'\'
        if substring(@dynamic_snapshot_location, len(@dynamic_snapshot_location) - len(@dynamic_snapshot_location_suffix) + 1, len(@dynamic_snapshot_location_suffix)) = @dynamic_snapshot_location_suffix
        begin
            exec @retcode = sys.sp_MSdeletefoldercontents @dynamic_snapshot_location
             
            if @retcode <> 0 or @@error <> 0
                return(1)
    
        end
    end

    return (0)
end

 
Last revision 2008RTM
See also

  sp_MSclear_dynamic_snapshot_location (Procedure)
sp_MSdropmergedynamicsnapshotjob (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