sp_adddistpublisher (Transact-SQL)

配置发布服务器以使用指定的分发数据库。 此存储过程在分发服务器上的任何数据库中执行。 请注意,在使用此存储过程之前,必须已经运行存储过程 sp_adddistributor (Transact-SQL)sp_adddistributiondb (Transact-SQL)

主题链接图标 Transact-SQL 语法约定

语法

sp_adddistpublisher [ @publisher= ] 'publisher'  
        , [ @distribution_db= ] 'distribution_db' 
    [ , [ @security_mode= ] security_mode ] 
    [ , [ @login= ] 'login' ] 
    [ , [ @password= ] 'password' ] 
    [ , [ @working_directory= ] 'working_directory' ] 
    [ , [ @trusted= ] 'trusted' ] 
    [ , [ @encrypted_password= ] encrypted_password ] 
    [ , [ @thirdparty_flag = ] thirdparty_flag ]
    [ , [ @publisher_type = ] 'publisher_type' ]

参数

  • [ @publisher=] 'publisher'
    发布服务器的名称。 publisher 的数据类型为 sysname,无默认值。

  • [ @distribution_db=] 'distribution_db'
    分发数据库的名称。 distributor_db 的数据类型为 sysname,无默认值。 复制代理使用该参数连接到发布服务器。

  • [ @security_mode=] security_mode
    所实现的安全模式。 该参数仅供复制代理用于连接到排队更新订阅的发布服务器或非 SQL Server 发布服务器。 security_mode 的数据类型为 int,可以是下列值之一。

    说明

    0

    分发服务器中的复制代理使用 SQL Server 身份验证连接到发布服务器。

    1(默认值)

    分发服务器中的复制代理使用 Windows 身份验证连接到发布服务器。

  • [ @login=] 'login'
    登录。 如果 security_mode0,则此参数是必需的。 login 的数据类型为 sysname,默认值为 NULL。 复制代理使用该参数连接到发布服务器。

  • [ @password=] 'password']
    密码。 password 的数据类型为 sysname,默认值为 NULL。 复制代理使用该参数连接到发布服务器。

    安全说明安全说明

    不要使用空密码。 请使用强密码。

  • [ @working_directory=] 'working_directory'
    用于存储发布的数据和架构文件的工作目录的名称。 working_directory 的数据类型为 nvarchar(255),默认值为该 SQL Server 实例的 ReplData 文件夹,例如“C:\Program Files\Microsoft SQL Server\MSSQL\MSSQ.1\ReplData”。 该名称应按 UNC 格式指定。

  • [ @trusted=] 'trusted'
    该参数已不推荐使用,提供它只是为了向后兼容。 trusted 的数据类型为 nvarchar(5),如果将它设置为除 false 以外的任何值,则将导致错误。

  • [ @encrypted_password=] encrypted_password
    不再支持设置 encrypted_password。 尝试将该 bit 参数设置为 1 会导致错误。

  • [ @thirdparty_flag =] thirdparty_flag
    发布服务器何时为 SQL Server。 thirdparty_flag 的数据类型为 bit,可以是下列值之一。

    说明

    0(默认值)

    SQL Server 数据库。

    1

    非 SQL Server 数据库。

  • [ @publisher_type= ] 'publisher_type'
    指定当发布服务器不是 SQL Server 时的发布服务器类型。 publisher_type 的数据类型为 sysname,可以为以下值之一。

    说明

    MSSQLSERVER 

    (默认值)

    指定 SQL Server 发布服务器。

    ORACLE

    指定标准的 Oracle 发布服务器。

    ORACLE GATEWAY

    指定 Oracle 网关发布服务器。

    有关 Oracle 发布服务器与 Oracle 网关发布服务器之间区别的详细信息,请参阅配置 Oracle 发布服务器

返回代码值

0(成功)或 1(失败)

注释

sp_adddistpublisher 用于快照复制、事务复制和合并复制。

示例

-- This script uses sqlcmd scripting variables. They are in the form
-- $(MyVariable). For information about how to use scripting variables  
-- on the command line and in SQL Server Management Studio, see the 
-- "Executing Replication Scripts" section in the topic
-- "Programming Replication Using System Stored Procedures".

-- Install the Distributor and the distribution database.
DECLARE @distributor AS sysname;
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
DECLARE @directory AS nvarchar(500);
DECLARE @publicationDB AS sysname;
-- Specify the Distributor name.
SET @distributor = $(DistPubServer);
-- Specify the distribution database.
SET @distributionDB = N'distribution';
-- Specify the Publisher name.
SET @publisher = $(DistPubServer);
-- Specify the replication working directory.
SET @directory = N'\\' + $(DistPubServer) + '\repldata';
-- Specify the publication database.
SET @publicationDB = N'AdventureWorks2012'; 

-- Install the server MYDISTPUB as a Distributor using the defaults,
-- including autogenerating the distributor password.
USE master
EXEC sp_adddistributor @distributor = @distributor;

-- Create a new distribution database using the defaults, including
-- using Windows Authentication.
USE master
EXEC sp_adddistributiondb @database = @distributionDB, 
    @security_mode = 1;
GO

-- Create a Publisher and enable AdventureWorks2012 for replication.
-- Add MYDISTPUB as a publisher with MYDISTPUB as a local distributor
-- and use Windows Authentication.
DECLARE @distributionDB AS sysname;
DECLARE @publisher AS sysname;
-- Specify the distribution database.
SET @distributionDB = N'distribution';
-- Specify the Publisher name.
SET @publisher = $(DistPubServer);

USE [distribution]
EXEC sp_adddistpublisher @publisher=@publisher, 
    @distribution_db=@distributionDB, 
    @security_mode = 1;
GO 

权限

只有 sysadmin 固定服务器角色的成员才能执行 sp_adddistpublisher

请参阅

参考

sp_changedistpublisher (Transact-SQL)

sp_dropdistpublisher (Transact-SQL)

sp_helpdistpublisher (Transact-SQL)

系统存储过程 (Transact-SQL)

概念

配置发布和分发

配置分发