Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSlocalizeinterruptedgenerations

  No additional text.


Syntax

create procedure sys.sp_MSlocalizeinterruptedgenerations @publication sysname=NULL
-- this proc loops over interrupted generations
-- and changes the guidsrc to a new value to basically give them a new identity, and closes them with genstatus=1 (local)
as
begin
    -- loop over interrupted generations
    -- determine lowest incomplete generation
        declare @guidsrc uniqueidentifier,
                        @gen bigint,
                        @art_nick int,
                        @retcode int,
                        @changecount int,
                        @replnick binary(6),
                        @nickbin binary(8)

        declare @pubid uniqueidentifier

    -- Security Checking
    -- sysadmin or db_owner or replication agent have access

    -- changing this for client requested snapshot. Relaxing this condition so that PAL users can call this
    -- added the optional publication parameter for this
    if @publication is not null and @publication != ''
    begin
        select @pubid = pubid from dbo.sysmergepublications where name=@publication and upper(publisher)=upper(publishingservername()) and publisher_db=DB_NAME()
        if (@pubid is NULL)
        begin
                raiserror(21040, 16, -1, @publication)
                return 1
        end
    end

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

     -- loop over interrupted generations
    while (1=1)
    begin
        -- determine lowest incomplete generation
        set @guidsrc = null
        set @changecount = 0

        select top 1 @guidsrc = guidsrc, @gen = generation, @art_nick = art_nick from dbo.MSmerge_genhistory with (NOLOCK)
                        where genstatus=0  -- incomplete gen
                        and generation not in (select gen_cur from dbo.sysmergearticles)  -- not a local incomplete gen
                        and coldate not in (select login_time from sys.dm_exec_sessions)  -- not a gen that currently receives replica updates from another db
                        order by generation asc

        if (@guidsrc is null)
            break

        delete from dbo.MSmerge_genhistory
        where generation = @gen
        and guidsrc = @guidsrc
        and genstatus = 0  -- incomplete gen
        and generation not in (select gen_cur from dbo.sysmergearticles)  -- not a local incomplete gen
        and coldate not in (select login_time from sys.dm_exec_sessions)  -- not a gen that currently receives replica updates from another db
        and not exists (select generation from dbo.MSmerge_contents where generation = @gen)
        and not exists (select generation from dbo.MSmerge_tombstone where generation = @gen)

        if @@rowcount = 0
        begin
            exec @retcode = sys.sp_MSget_gen_approx_changecount @gen, @changecount OUTPUT
            if @retcode <> 0 or @@error <> 0
                    return 1

            exec @retcode = sys.sp_MSmap_generation_to_partitionids @gen, @art_nick
            if @retcode <> 0 or @@error <> 0
                    return 1

            -- Ensure that localized generations regenerate the nicknames array for the new generation
            exec sys.sp_MSgetreplnick @replnick = @replnick out
            if @@error <> 0
                    return 1

            -- Append guard byte
            set @nickbin= @replnick + 0xFF

            update dbo.MSmerge_genhistory set guidsrc = newid(), genstatus = 1, coldate = getdate(), changecount = @changecount, nicknames = @nickbin
            where generation = @gen
            and guidsrc = @guidsrc
            and genstatus=0  -- incomplete gen
            and generation not in (select gen_cur from dbo.sysmergearticles)  -- not a local incomplete gen
            and coldate not in (select login_time from sys.dm_exec_sessions)  -- not a gen that currently receives replica updates from another db
        end
    end

    if @@error <> 0
        return 1
    else
        return 0
end

 
Last revision 2008RTM
See also

  sp_MSdrop_rlrecon (Procedure)
sp_MSmakegenerationold (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