Home Microsoft SQL Server DigiMailing iRN Contact
    Keyword



sys.sp_MSrepl_addscriptexec

  No additional text.


Syntax
create procedure sys.sp_MSrepl_addscriptexec
(
    @publication    sysname,
    @scriptfile        nvarchar(4000),
    @skiperror        bit
)
AS
BEGIN
declare @directory nvarchar(4000)
declare @cmd nvarchar(4000)
declare @filename nvarchar(1024)
declare @subdirectory nvarchar(1024)
declare @artid int
declare @pubid int
declare @repl_freq int
declare @retcode int
declare @merge_pubid uniqueidentifier
declare @schemaversion int
declare @schemaguid uniqueidentifier

set nocount on

exec @retcode = sys.sp_MSreplcheck_publish
if @@ERROR <> 0 or @retcode <> 0
    return(1)

-- Check to see if the database has been activated for publication.
IF sys.fn_MSrepl_ispublished(DB_NAME()) <> 1
BEGIN
    RAISERROR (14013, 16, -1)
    RETURN (1)
END

IF @publication IS NULL
BEGIN
    RAISERROR (14043, 16, -1, '@publication', 'sp_MSrepl_addscriptexec')
    RETURN (1)
END
ELSE
BEGIN
    EXECUTE @retcode = sys.sp_validname @publication
        IF @retcode <> 0
            RETURN (1)
END

-- Make sure the publication is available before any cmdshell work.
if object_id('syspublications') is not NULL
begin
    select @pubid = pubid, @repl_freq = repl_freq  from syspublications where name = @publication
    if @pubid is not null
    begin
        -- Doesn't make sense to post for every article in the publication,
        -- but artid is required for sp_replpostcmd to work, so just pick one.
        select top 1 @artid = artid from sysarticles where pubid = @pubid
        if(@artid is null)
        begin
            RAISERROR (21332, 16, -1, @publication)
            return (1)
        end
        if(@repl_freq = 1) -- don't try to post to snapshot publication, it won't work.
        begin
            RAISERROR (21340, 16, -1, @publication)
            return (1)
        end
    end
end
if object_id('sysmergepublications') is not NULL
begin
    select @merge_pubid = pubid  from dbo.sysmergepublications where name = @publication and publisher_db = db_name() and UPPER(publisher) = UPPER(publishingservername())
    if @merge_pubid is not null
    begin
        select @schemaversion = 1 + max(schemaversion) from dbo.sysmergeschemachange
        if @schemaversion is null
            select @schemaversion = 1

        select @schemaguid = newid()
    end
end

if(@pubid is null and @merge_pubid is null)
begin
    RAISERROR (21332, 16, -1, @publication)
    return (1)
end

IF @scriptfile IS NULL
BEGIN
    RAISERROR (14043, 16, -1, '@scriptfile', 'sp_MSrepl_addscriptexec')
    RETURN (1)
END

if (@merge_pubid is not NULL)
begin
    exec @retcode = sys.sp_MScopyscriptfile_merge @publication, @scriptfile, @cmd=@cmd output
    if @retcode <>0 or @@ERROR<>0
        return (1)
end
else
begin
    exec @retcode = sys.sp_MScopyscriptfile @scriptfile, @cmd=@cmd output
    if @retcode <>0 or @@ERROR<>0
        return (1)
end

select @cmd = convert(nchar(1), @skiperror) + @cmd
if @pubid is not null
    exec @retcode = sys.sp_replpostcmd 0, @pubid, @artid, 46, @cmd
if @merge_pubid is not null
    exec @retcode = sys.sp_MSinsertschemachange @merge_pubid, NULL, @schemaversion, @schemaguid, 46, @cmd
if @retcode <>0 or @@ERROR<>0
    return (1)
return (0)
END

 
Last revision 2008RTM
See also

  sp_addscriptexec (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