Sql server 使用脚本的事务复制
我能够使用SSM配置事务复制,并且它工作正常。但我想使用脚本对其进行配置,以便从c#/vb应用程序中使用它Sql server 使用脚本的事务复制,sql-server,sql-server-2008,replication,sql-server-agent,transactional-replication,Sql Server,Sql Server 2008,Replication,Sql Server Agent,Transactional Replication,我能够使用SSM配置事务复制,并且它工作正常。但我想使用脚本对其进行配置,以便从c#/vb应用程序中使用它 有什么方法可以做到这一点吗?如果使用SSM完成事务复制的所有步骤,那么使用脚本并不复杂 DECLARE @returncode int EXEC @returncode = xp_cmdshell 'dtexec /f "C:\thePackage.dtsx"' 请仔细观察,当您配置分发、发布和订阅时,SSMS为您提供了在每个步骤中生成脚本的选项 您可以使用生成的脚本 但唯一的区别是在出
有什么方法可以做到这一点吗?如果使用SSM完成事务复制的所有步骤,那么使用脚本并不复杂
DECLARE @returncode int
EXEC @returncode = xp_cmdshell 'dtexec /f "C:\thePackage.dtsx"'
请仔细观察,当您配置分发、发布和订阅时,SSMS为您提供了在每个步骤中生成脚本的选项
您可以使用生成的脚本
但唯一的区别是在出版物中添加文章时。您可以使用以下代码添加文章
declare @name nvarchar(50)
declare curname cursor for
select name from sysobjects where type = 'U'
open curname
fetch next from curname into @name
while @@FETCH_STATUS = 0
begin
if exists(select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where CONSTRAINT_TYPE = 'PRIMARY KEY' AND TABLE_NAME = @name AND TABLE_SCHEMA = 'dbo')
begin
exec sp_addarticle
@publication = N'publication_name', @article = @name, @source_owner = N'dbo',
@source_object = @name, @type = N'logbased', @description = null, @creation_script = null,
@pre_creation_cmd = N'drop', @schema_option = 0x000000000803509F,
@identityrangemanagementoption = N'manual', @destination_table = @name,
@destination_owner = N'dbo', @vertical_partition = N''
end
fetch next from curname into @name
end
close curname
deallocate curname
或者,您可以在BOL中查看sp_addpublication、sp_addarticle和sp_addsubscription。是@name的更好类型。您的脚本不能用于超过50个字符的名称。sysname是对象名的内部类型,相当于nvarchar(128)。