本主题介绍如何使用 SQL Server Management Studio、Transact-SQL 或复制管理对象(RMO)在 SQL Server 2014 中创建发布。
本主题内容
准备工作:
创建出版物和定义文章,请使用:
在您开始之前
局限性与限制
- 发布和项目名称不能包含以下任何字符:%、* 、 [ 、 [ 、 ] |, : , " , ? , ' , \ , / , < , > 如果数据库中的对象包含这些字符中的任何一个,并且要复制这些字符,则必须指定与“ 项目属性 - <项目> ”对话框中的对象名称不同的项目名称,该名称可从向导中的“ 项目 ”页获取。
安全
如果可能,请提示用户在运行时输入安全凭据。 如果必须存储凭据,请使用 Microsoft Windows .NET Framework 提供的 加密服务 。
使用 SQL Server Management Studio
使用“新建发布向导”创建出版物并定义文章。 创建发布后,在 “发布属性 - <发布> ”对话框中查看和修改发布属性。 有关从 Oracle 数据库创建发布的信息,请参阅 从 Oracle 数据库创建发布。
创建出版物并定义文章
在 Microsoft SQL Server Management Studio 中连接到发布者,然后展开服务器节点。
展开 “复制 ”文件夹,然后右键单击 “本地发布 ”文件夹。
单击“ 新建出版物”。
请按照【新建发布向导】中的页面完成以下步骤:
如果未在服务器上配置分发服务器,请指定分发服务器。 有关配置分发的详细信息,请参阅 “配置发布和分发”。
如果在 分发服务器 页面指定发布服务器将充当其自己的分发服务器(本地分发服务器),并且服务器未配置为分发服务器,则新建发布向导将对服务器进行配置。 将在“快照文件夹”页上为分发服务器指定默认 快照文件夹 。 快照文件夹只是你已指定为共享的目录;从此文件夹读取和写入的代理必须具有足够的权限才能访问它。 有关适当保护文件夹的详细信息,请参阅 “保护快照文件夹”。
如果指定另一台服务器应充当分发服务器,则必须在 “管理密码 ”页上输入密码,以便从发布服务器连接到分发服务器的连接。 此密码必须与在远程分发服务器上启用发布服务器时指定的密码匹配。
有关详细信息,请参阅 “配置分发”。
选择出版物数据库。
选择发布类型。 有关详细信息,请参阅 复制类型。
指定要发布的数据和数据库对象;(可选)从表项目筛选列,并设置项目属性。
(可选)从表文章中筛选行。 有关详细信息,请参阅 “筛选已发布数据”。
设置快照代理时间表。
指定以下复制代理运行并建立连接的凭据:
- 所有发布的快照代理。
- 所有事务性发布的日志读取器代理。
- 用于允许更新订阅的事务性发布的队列读取器代理。
(可选)编写发布脚本。 有关详细信息,请参阅 脚本复制。
指定发布的名称。
使用 Transact-SQL
可以通过编程方式使用复制存储过程创建发布。 使用的存储过程将取决于所创建的发布类型。
创建快照或事务发布
在发布者的发布数据库上,执行sp_replicationdboption(Transact-SQL),以通过快照或事务复制使当前数据库能够发布。
对于事务性发布,请确定发布数据库中是否存在日志读取代理作业。 (快照发布不需要此步骤。
如果发布数据库存在日志读取器代理作业,请转到步骤 3。
如果不确定已发布数据库是否存在日志读取器代理作业,请在发布者的发布数据库上执行sp_helplogreader_agent(Transact-SQL)。
如果结果集为空,请创建日志读取器代理作业。 在发布服务器上,执行sp_addlogreader_agent(Transact-SQL)。 指定@job_name的代理在 Microsoft Windows 下运行,并提供@password的凭据。 如果代理在连接到发布服务器时将使用 SQL Server 身份验证,则还必须为 @publisher_security_mode 指定值 0,并为@publisher_login和@publisher_password指定Microsoft SQL Server 登录信息。 继续执行步骤 3。
在发布服务器上,执行sp_addpublication(Transact-SQL)。 请为@publication指定发布名称,并为@repl_freq参数指定一个值,如果是快照发布,请使用
snapshot
,如果是事务发布,请使用continuous
。 指定任何其他发布选项。 这定义了出版物。注释
发布名称不能包含以下字符:
% * [ ] |: " ? \ / <>
在发布服务器上,执行sp_addpublication_snapshot(Transact-SQL)。 请在步骤 3 中指定用于@publication的发布名称,以及用于快照代理运行的 Windows 凭据,包括@snapshot_job_name和@password。 如果在连接到发布服务器时代理将使用 SQL Server 身份验证,则还必须为 @publisher_security_mode 指定值 0,并为@publisher_login和@publisher_password指定 SQL Server 登录信息。 这会为发布创建快照代理作业。
重要
在配置发布者与远程分发者时,为所有配置参数(包括 job_login 和 job_password)提供的值将以明文形式发送到分发者。 在执行此存储过程之前,应加密发布服务器与其远程分发服务器之间的连接。 有关详细信息,请参阅启用数据库引擎的加密连接(SQL Server 配置管理器)。
将项目添加到发布。 有关详细信息,请参阅 定义项目。
启动快照代理作业,生成此发布的初始快照。 有关详细信息,请参阅 “创建并应用初始快照”。
创建合并版发布
在发布者处,执行 sp_replicationdboption(Transact-SQL),以使用合并复制将当前数据库发布。
在发布服务器上,对发布数据库执行sp_addmergepublication(Transact-SQL)。 为@publication指定一个名称以及任何其他发布选项。 这定义发布。
注释
发布名称不能包含以下字符:
% * [ ] |: " ? \ / <>
在发布服务器上,执行sp_addpublication_snapshot(Transact-SQL)。 指定步骤 2 中使用的发布名称用于@publication,以及用于@snapshot_job_name和@password的快照代理运行的 Windows 凭据。 如果在连接到发布服务器时代理将使用 SQL Server 身份验证,则还必须为 @publisher_security_mode 指定值 0,并为@publisher_login和@publisher_password指定 SQL Server 登录信息。 这会为发布创建快照代理作业。
重要
配置发布服务器与远程分发服务器时,提供的所有参数值(包括 job_login 和 job_password)将以纯文本形式发送到分发服务器。 在执行此存储过程之前,应加密发布服务器与其远程分发服务器之间的连接。 有关详细信息,请参阅启用数据库引擎的加密连接(SQL Server 配置管理器)。
将文章添加到发布中。 有关详细信息,请参阅 定义项目。
启动快照代理作业,生成此发布的初始快照。 有关详细信息,请参阅 “创建并应用初始快照”。
示例 (Transact-SQL)
此示例创建事务性发布。 脚本变量用于传递为快照代理和日志读取器代理创建作业所需的 Windows 凭据。
-- To avoid storing the login and password in the script file, the values
-- are passed into SQLCMD as scripting variables. 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".
DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publicationDB = N'AdventureWorks';
SET @publication = N'AdvWorksProductTran';
-- Windows account used to run the Log Reader and Snapshot Agents.
SET @login = $(Login);
-- This should be passed at runtime.
SET @password = $(Password);
-- Enable transactional or snapshot replication on the publication database.
EXEC sp_replicationdboption
@dbname=@publicationDB,
@optname=N'publish',
@value = N'true';
-- Execute sp_addlogreader_agent to create the agent job.
EXEC sp_addlogreader_agent
@job_login = @login,
@job_password = @password,
-- Explicitly specify the use of Windows Integrated Authentication (default)
-- when connecting to the Publisher.
@publisher_security_mode = 1;
-- Create a new transactional publication with the required properties.
EXEC sp_addpublication
@publication = @publication,
@status = N'active',
@allow_push = N'true',
@allow_pull = N'true',
@independent_agent = N'true';
-- Create a new snapshot job for the publication, using a default schedule.
EXEC sp_addpublication_snapshot
@publication = @publication,
@job_login = @login,
@job_password = @password,
-- Explicitly specify the use of Windows Integrated Authentication (default)
-- when connecting to the Publisher.
@publisher_security_mode = 1;
GO
此示例用于创建合并发布。 脚本变量用于传递为快照代理创建作业所需的 Windows 凭据。
-- To avoid storing the login and password in the script file, the value
-- is passed into SQLCMD as a scripting variable. 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".
--Declarations for adding a merge publication
DECLARE @publicationDB AS sysname;
DECLARE @publication AS sysname;
DECLARE @login AS sysname;
DECLARE @password AS sysname;
SET @publicationDB = N'AdventureWorks2012';
SET @publication = N'AdvWorksSalesOrdersMerge';
SET @login = $(Login);
SET @password = $(Password);
-- Enable merge replication on the publication database, using defaults.
USE master
EXEC sp_replicationdboption
@dbname=@publicationDB,
@optname=N'merge publish',
@value = N'true'
-- Create a new merge publication, explicitly setting the defaults.
USE [AdventureWorks2012]
EXEC sp_addmergepublication
-- These parameters are optional.
@publication = @publication,
-- optional parameters
@description = N'Merge publication of AdventureWorks2012.',
@publication_compatibility_level = N'120RTM';
-- Create a new snapshot job for the publication.
EXEC sp_addpublication_snapshot
@publication = @publication,
@job_login = @login,
@job_password = @password;
GO
使用复制管理对象 (RMO)
可以使用复制管理对象(RMO)以编程方式创建发布。 用于创建发布的 RMO 类取决于所创建的发布类型。
创建快照或事务发布
使用 ServerConnection 类创建与发布服务器的连接。
为发布数据库创建类的 ReplicationDatabase 实例,将 ConnectionContext 属性设置为步骤 1 中的 ServerConnection 实例,并调用 LoadProperties 该方法。 如果 LoadProperties 返回
false
,请验证数据库是否存在。EnabledTransPublishing如果该属性为
false
,则将其设置为true
。对于交易性出版物,请检查LogReaderAgentExists属性的值。 如果此属性是
true
,则此数据库的日志读取代理作业已存在。 如果此属性为false
,请执行以下作:设置 Login 和 Password 或 SecurePassword* 字段,以在 LogReaderAgentProcessSecurity 中提供用于运行日志读取器代理的 Microsoft Windows 帐户的凭据。
注释
创建由某个固定服务器角色
sysadmin
成员创建的发布时,不需要设置LogReaderAgentProcessSecurity。 在这种情况下,代理将模拟 SQL Server 代理帐户。 有关详细信息,请参阅 复制代理安全模式。(可选)使用 SQL Server 身份验证连接到发布服务器时,设置 LogReaderAgentPublisherSecurity 的 SqlStandardLogin 和 SqlStandardPassword 或 SecureSqlStandardPassword 字段。
CreateLogReaderAgent调用该方法为数据库创建日志读取器代理作业。
创建类的 TransPublication 实例,并为此对象设置以下属性:
已发布的数据库 DatabaseName的名称。
为Name的出版物的名称。
要么Transactional,要么Snapshot。
Login和Password字段用于提供运行快照代理的 Windows 帐户的凭据SnapshotGenerationAgentProcessSecurity。 当快照代理与本地分发服务器建立连接,并在使用 Windows 身份验证时用于任何远程连接时,也会使用此帐户。
注释
当
sysadmin
固定服务器角色的成员创建发布时,不需要设置SnapshotGenerationAgentProcessSecurity。 在这种情况下,代理将模拟 SQL Server 代理帐户。 有关详细信息,请参阅 复制代理安全模式。(可选)在使用 SQL Server 身份验证连接到发布服务器时的 SqlStandardLogin 和 SqlStandardPassword 或 SecureSqlStandardPassword 字段 SnapshotGenerationAgentPublisherSecurity。
(可选)使用非独占逻辑 OR 运算符(
|
在 Visual C# 和 Visual Basic 中)和Or
排他逻辑 OR 运算符(^
在 Visual C# 和Xor
Visual Basic 中)设置 PublicationAttributes 属性的值 Attributes 。(可选)当发布者是非 SQL Server 发布者时,PublisherName 的发布者名称。
调用Create方法以创建发布。
重要
在配置发布服务器与远程分发服务器时,所有属性(包括 SnapshotGenerationAgentProcessSecurity)的值都会以纯文本形式发送给分发服务器。 在调用 Create 该方法之前,应加密发布服务器与其远程分发服务器之间的连接。 有关详细信息,请参阅启用数据库引擎的加密连接(SQL Server 配置管理器)。
调用CreateSnapshotAgent方法来为发布创建快照代理作业。
创建合并出版物
使用 ServerConnection 类创建与发布服务器的连接。
为发布数据库创建类的 ReplicationDatabase 实例,将 ConnectionContext 属性设置为步骤 1 中的 ServerConnection 实例,并调用 LoadProperties 该方法。 如果 LoadProperties 返回
false
,请验证数据库是否存在。如果 EnabledMergePublishing 属性是
false
,请将其设置为true
并调用 CommitPropertyChanges。创建类的 MergePublication 实例,并为此对象设置以下属性:
已发布的数据库 DatabaseName的名称。
Name 的出版物名称。
Login 和 Password 字段在 SnapshotGenerationAgentProcessSecurity 中,用于提供运行快照代理的 Windows 帐户的凭据。 当快照代理与本地分发服务器建立连接,并在使用 Windows 身份验证时用于任何远程连接时,也会使用此帐户。
注释
当发布由
sysadmin
固定服务器角色的成员创建时,无需设置SnapshotGenerationAgentProcessSecurity。 有关详细信息,请参阅 复制代理安全模式。(可选)使用非独占逻辑 OR 运算符(
|
在 Visual C# 和 Visual Basic 中)和Or
排他逻辑 OR 运算符(^
在 Visual C# 和Xor
Visual Basic 中)设置 PublicationAttributes 属性的值 Attributes 。
调用Create方法以创建发布。
重要
当使用远程分发服务器配置发布服务器时,所有属性(包括 SnapshotGenerationAgentProcessSecurity)提供的值都会以纯文本形式传送至分发服务器。 在调用 Create 该方法之前,应加密发布服务器与其远程分发服务器之间的连接。 有关详细信息,请参阅启用数据库引擎的加密连接(SQL Server 配置管理器)。
CreateSnapshotAgent调用该方法为发布创建快照代理作业。
示例 (RMO)
此示例为 AdventureWorks 数据库启用事务性发布,定义日志读取器代理任务,并创建 AdvWorksProductTran 发布。 必须为此出版物定义文章。 在运行时传递创建日志读取器代理作业和快照代理作业所需的 Windows 帐户凭据。 若要了解如何使用 RMO 定义快照和事务项目,请参阅 “定义项目”。
// Set the Publisher, publication database, and publication names.
string publicationName = "AdvWorksProductTran";
string publicationDbName = "AdventureWorks2012";
string publisherName = publisherInstance;
ReplicationDatabase publicationDb;
TransPublication publication;
// Create a connection to the Publisher using Windows Authentication.
ServerConnection conn;
conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Enable the AdventureWorks2012 database for transactional publishing.
publicationDb = new ReplicationDatabase(publicationDbName, conn);
// If the database exists and is not already enabled,
// enable it for transactional publishing.
if (publicationDb.LoadProperties())
{
if (!publicationDb.EnabledTransPublishing)
{
publicationDb.EnabledTransPublishing = true;
}
// If the Log Reader Agent does not exist, create it.
if (!publicationDb.LogReaderAgentExists)
{
// Specify the Windows account under which the agent job runs.
// This account will be used for the local connection to the
// Distributor and all agent connections that use Windows Authentication.
publicationDb.LogReaderAgentProcessSecurity.Login = winLogin;
publicationDb.LogReaderAgentProcessSecurity.Password = winPassword;
// Explicitly set authentication mode for the Publisher connection
// to the default value of Windows Authentication.
publicationDb.LogReaderAgentPublisherSecurity.WindowsAuthentication = true;
// Create the Log Reader Agent job.
publicationDb.CreateLogReaderAgent();
}
}
else
{
throw new ApplicationException(String.Format(
"The {0} database does not exist at {1}.",
publicationDb, publisherName));
}
// Set the required properties for the transactional publication.
publication = new TransPublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Specify a transactional publication (the default).
publication.Type = PublicationType.Transactional;
// Activate the publication so that we can add subscriptions.
publication.Status = State.Active;
// Enable push and pull subscriptions and independent Distribition Agents.
publication.Attributes |= PublicationAttributes.AllowPull;
publication.Attributes |= PublicationAttributes.AllowPush;
publication.Attributes |= PublicationAttributes.IndependentAgent;
// Specify the Windows account under which the Snapshot Agent job runs.
// This account will be used for the local connection to the
// Distributor and all agent connections that use Windows Authentication.
publication.SnapshotGenerationAgentProcessSecurity.Login = winLogin;
publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword;
// Explicitly set the security mode for the Publisher connection
// Windows Authentication (the default).
publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = true;
if (!publication.IsExistingObject)
{
// Create the transactional publication.
publication.Create();
// Create a Snapshot Agent job for the publication.
publication.CreateSnapshotAgent();
}
else
{
throw new ApplicationException(String.Format(
"The {0} publication already exists.", publicationName));
}
}
catch (Exception ex)
{
// Implement custom application error handling here.
throw new ApplicationException(String.Format(
"The publication {0} could not be created.", publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Set the Publisher, publication database, and publication names.
Dim publicationName As String = "AdvWorksProductTran"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publisherName As String = publisherInstance
Dim publicationDb As ReplicationDatabase
Dim publication As TransPublication
' Create a connection to the Publisher using Windows Authentication.
Dim conn As ServerConnection
conn = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Enable the AdventureWorks2012 database for transactional publishing.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
' If the database exists and is not already enabled,
' enable it for transactional publishing.
If publicationDb.LoadProperties() Then
If Not publicationDb.EnabledTransPublishing Then
publicationDb.EnabledTransPublishing = True
End If
' If the Log Reader Agent does not exist, create it.
If Not publicationDb.LogReaderAgentExists Then
' Specify the Windows account under which the agent job runs.
' This account will be used for the local connection to the
' Distributor and all agent connections that use Windows Authentication.
publicationDb.LogReaderAgentProcessSecurity.Login = winLogin
publicationDb.LogReaderAgentProcessSecurity.Password = winPassword
' Explicitly set authentication mode for the Publisher connection
' to the default value of Windows Authentication.
publicationDb.LogReaderAgentPublisherSecurity.WindowsAuthentication = True
' Create the Log Reader Agent job.
publicationDb.CreateLogReaderAgent()
End If
Else
Throw New ApplicationException(String.Format( _
"The {0} database does not exist at {1}.", _
publicationDb, publisherName))
End If
' Set the required properties for the transactional publication.
publication = New TransPublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Specify a transactional publication (the default).
publication.Type = PublicationType.Transactional
'Enable push and pull subscriptions and independent Distribition Agents.
publication.Attributes = _
publication.Attributes Or PublicationAttributes.AllowPull
publication.Attributes = _
publication.Attributes Or PublicationAttributes.AllowPush
publication.Attributes = _
publication.Attributes Or PublicationAttributes.IndependentAgent
' Activate the publication so that we can add subscriptions.
publication.Status = State.Active
' Specify the Windows account under which the Snapshot Agent job runs.
' This account will be used for the local connection to the
' Distributor and all agent connections that use Windows Authentication.
publication.SnapshotGenerationAgentProcessSecurity.Login = winLogin
publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword
' Explicitly set the security mode for the Publisher connection
' Windows Authentication (the default).
publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = True
If Not publication.IsExistingObject Then
' Create the transactional publication.
publication.Create()
' Create a Snapshot Agent job for the publication.
publication.CreateSnapshotAgent()
Else
Throw New ApplicationException(String.Format( _
"The {0} publication already exists.", publicationName))
End If
Catch ex As Exception
' Implement custom application error handling here.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be created.", publicationName), ex)
Finally
conn.Disconnect()
End Try
此示例启用 AdventureWorks 数据库进行合并发布,并创建 AdvWorksSalesOrdersMerge 发布项目。 仍必须为此发布定义文章。 在运行时传递创建快照代理作业所需的 Windows 帐户凭据。 若要了解如何使用 RMO 定义合并项目,请参阅 “定义项目”。
// Set the Publisher, publication database, and publication names.
string publisherName = publisherInstance;
string publicationName = "AdvWorksSalesOrdersMerge";
string publicationDbName = "AdventureWorks2012";
ReplicationDatabase publicationDb;
MergePublication publication;
// Create a connection to the Publisher.
ServerConnection conn = new ServerConnection(publisherName);
try
{
// Connect to the Publisher.
conn.Connect();
// Enable the database for merge publication.
publicationDb = new ReplicationDatabase(publicationDbName, conn);
if (publicationDb.LoadProperties())
{
if (!publicationDb.EnabledMergePublishing)
{
publicationDb.EnabledMergePublishing = true;
}
}
else
{
// Do something here if the database does not exist.
throw new ApplicationException(String.Format(
"The {0} database does not exist on {1}.",
publicationDb, publisherName));
}
// Set the required properties for the merge publication.
publication = new MergePublication();
publication.ConnectionContext = conn;
publication.Name = publicationName;
publication.DatabaseName = publicationDbName;
// Enable precomputed partitions.
publication.PartitionGroupsOption = PartitionGroupsOption.True;
// Specify the Windows account under which the Snapshot Agent job runs.
// This account will be used for the local connection to the
// Distributor and all agent connections that use Windows Authentication.
publication.SnapshotGenerationAgentProcessSecurity.Login = winLogin;
publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword;
// Explicitly set the security mode for the Publisher connection
// Windows Authentication (the default).
publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = true;
// Enable Subscribers to request snapshot generation and filtering.
publication.Attributes |= PublicationAttributes.AllowSubscriberInitiatedSnapshot;
publication.Attributes |= PublicationAttributes.DynamicFilters;
// Enable pull and push subscriptions.
publication.Attributes |= PublicationAttributes.AllowPull;
publication.Attributes |= PublicationAttributes.AllowPush;
if (!publication.IsExistingObject)
{
// Create the merge publication.
publication.Create();
// Create a Snapshot Agent job for the publication.
publication.CreateSnapshotAgent();
}
else
{
throw new ApplicationException(String.Format(
"The {0} publication already exists.", publicationName));
}
}
catch (Exception ex)
{
// Implement custom application error handling here.
throw new ApplicationException(String.Format(
"The publication {0} could not be created.", publicationName), ex);
}
finally
{
conn.Disconnect();
}
' Set the Publisher, publication database, and publication names.
Dim publisherName As String = publisherInstance
Dim publicationName As String = "AdvWorksSalesOrdersMerge"
Dim publicationDbName As String = "AdventureWorks2012"
Dim publicationDb As ReplicationDatabase
Dim publication As MergePublication
' Create a connection to the Publisher.
Dim conn As ServerConnection = New ServerConnection(publisherName)
Try
' Connect to the Publisher.
conn.Connect()
' Enable the database for merge publication.
publicationDb = New ReplicationDatabase(publicationDbName, conn)
If publicationDb.LoadProperties() Then
If Not publicationDb.EnabledMergePublishing Then
publicationDb.EnabledMergePublishing = True
End If
Else
' Do something here if the database does not exist.
Throw New ApplicationException(String.Format( _
"The {0} database does not exist on {1}.", _
publicationDb, publisherName))
End If
' Set the required properties for the merge publication.
publication = New MergePublication()
publication.ConnectionContext = conn
publication.Name = publicationName
publication.DatabaseName = publicationDbName
' Enable precomputed partitions.
publication.PartitionGroupsOption = PartitionGroupsOption.True
' Specify the Windows account under which the Snapshot Agent job runs.
' This account will be used for the local connection to the
' Distributor and all agent connections that use Windows Authentication.
publication.SnapshotGenerationAgentProcessSecurity.Login = winLogin
publication.SnapshotGenerationAgentProcessSecurity.Password = winPassword
' Explicitly set the security mode for the Publisher connection
' Windows Authentication (the default).
publication.SnapshotGenerationAgentPublisherSecurity.WindowsAuthentication = True
' Enable Subscribers to request snapshot generation and filtering.
publication.Attributes = publication.Attributes Or _
PublicationAttributes.AllowSubscriberInitiatedSnapshot
publication.Attributes = publication.Attributes Or _
PublicationAttributes.DynamicFilters
' Enable pull and push subscriptions
publication.Attributes = publication.Attributes Or _
PublicationAttributes.AllowPull
publication.Attributes = publication.Attributes Or _
PublicationAttributes.AllowPush
If Not publication.IsExistingObject Then
' Create the merge publication.
publication.Create()
' Create a Snapshot Agent job for the publication.
publication.CreateSnapshotAgent()
Else
Throw New ApplicationException(String.Format( _
"The {0} publication already exists.", publicationName))
End If
Catch ex As Exception
' Implement custom application error handling here.
Throw New ApplicationException(String.Format( _
"The publication {0} could not be created.", publicationName), ex)
Finally
conn.Disconnect()
End Try
另请参阅
将 sqlcmd 与脚本变量结合使用
发布数据和数据库对象
复制管理对象概念
定义文章
查看和修改发布属性
配置分发
保护分发服务器
保护发布者