我正在使用sql server 2012和事务复制。我试图复制一个在权限中附加了特定数据库角色的视图。这是视图的复制脚本
:setvar SubscriberDB "ReplicationSubscriberDB"
:setvar SubscriberServerName "HYDHTC0131320D\MSSQLSERVER2"
:setvar PublisherDB "PublisherDB"
:setvar PublisherServerName "HYDHTC0131320D"
:setvar ReplicationAccount "myusername"
:setvar ReplicationAccountPassword "mypassword"
GO
:on error exit
GO
exec sp_addpublication @publication = N'DepartmentsView', @description = N'Transactional publication of database from Publisher ''$(PublisherServerName)''.', @sync_method = N'concurrent', @retention = 0, @allow_push = N'true', @allow_pull = N'true', @allow_anonymous = N'false', @enabled_for_internet = N'false', @snapshot_in_defaultfolder = N'true', @compress_snapshot = N'false', @allow_subscription_copy = N'false', @add_to_active_directory = N'false', @repl_freq = N'continuous', @status = N'active', @independent_agent = N'true', @immediate_sync = N'true', @allow_sync_tran = N'false', @autogen_sync_procs = N'false', @allow_queued_tran = N'false', @allow_dts = N'false', @replicate_ddl = 1, @allow_initialize_from_backup = N'false', @enabled_for_p2p = N'false', @enabled_for_het_sub = N'false'
GO
exec sp_addpublication_snapshot @publication = N'DepartmentsView', @frequency_type = 1, @frequency_interval = 0, @frequency_relative_interval = 0, @frequency_recurrence_factor = 0, @frequency_subday = 0, @frequency_subday_interval = 0, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 0, @active_end_date = 0, @job_login = N'$(ReplicationAccount)', @job_password = '$(ReplicationAccountPassword)', @publisher_security_mode = 1
GO
exec sp_addarticle @publication = N'DepartmentsView', @article = N'vwDepartments', @source_owner = N'dbo', @source_object = N'vwDepartments', @type = N'view schema only', @description = null, @creation_script = null, @pre_creation_cmd = N'drop', @schema_option = 0x48000001, @destination_table = N'vwDepartments', @destination_owner = N'dbo'
GO
EXEC sp_startpublication_snapshot @publication = N'DepartmentsView'
GO
use [$(PublisherDB)]
GO
exec sp_addsubscription @publication = N'DepartmentsView', @subscriber = N'$(SubscriberServerName)', @destination_db = N'$(SubscriberDB)', @subscription_type = N'Push', @sync_type = N'automatic', @article = N'all', @update_mode = N'read only', @subscriber_type = 0
GO
exec sp_addpushsubscription_agent @publication = N'DepartmentsView', @subscriber = N'$(SubscriberServerName)', @subscriber_db = N'$(SubscriberDB)', @job_login = N'$(ReplicationAccount)', @job_password = '$(ReplicationAccountPassword)', @subscriber_security_mode = 1, @frequency_type = 4, @frequency_interval = 1, @frequency_relative_interval = 0, @frequency_recurrence_factor = 0, @frequency_subday = 8, @frequency_subday_interval = 6, @active_start_time_of_day = 0, @active_end_time_of_day = 235959, @active_start_date = 20120607, @active_end_date = 99991231, @enabled_for_syncmgr = N'False', @dts_package_location = N'Distributor'
GO
复制后,视图即被创建,但角色未附加到视图的权限。此角色出现在发布者和订阅者数据库中。并且此角色分配给视图中使用的表,并且表存在于两个数据库中。
我尝试将schema_option设置为0x48000001,即
我也经历过这篇文章http://social.msdn.microsoft.com/Forums/en-US/sqlreplication/thread/a4fa2d32-00ea-47a7-9276-52764fab72ae/,其中说上面的schema_option值应该有效。或者我们必须在sp_addpublication中使用@post_snapshot_script。
我尝试使用@post_snapshot_script并且它正在运行,但我不想使用这种方法。
请让我知道如何解决这个问题。
提前感谢。
答案 0 :(得分:0)
这是SQL Server 2012中的一个已知问题。由于快照代理中存在错误,因此会出现此问题。现在有一个解决方法,直到Microsoft发布此问题的修复程序: 1.打开快照文件夹。 2.通过添加所需权限来编辑视图的.sch文件。
订阅者可以在此之后获得正确的快照。
答案 1 :(得分:0)
我遇到了同样的已知错误。结果是在发布的“运行附加脚本 - 应用快照后”属性中指定权限授予脚本。