Sql-Server
如何通過 T-SQL 更改發佈設置?
我設置了一個新伺服器來託管一些數據庫出版物。
在同一台伺服器上,我設置了分發伺服器 db。
一切順利,然後在事務複製上執行發布的快照時:
問題?我可以從本地伺服器更改該伺服器上的發布並重新執行快照嗎?
從我的本地 ssms 連接到發布所在的伺服器並執行以下命令來更改發布並將快照文件夾設置到不同的位置:
下面的腳本還會將該訂閱標記為重新初始化並啟動快照代理。
use [my_database_publisher] EXEC sp_changepublication @publication = 'My_Publication_Pub', --Enter your publication name @property = 'alt_snapshot_folder' , @value = 'G:\Backup\ReplData', @force_invalidate_snapshot=1 GO --Cannot make the change because a snapshot is already generated. --Set @force_invalidate_snapshot to 1 to force the change and invalidate the existing snapshot. --================================================================================================================================================ -- Marks the subscription for reinitialization. This stored procedure is executed at the Publisher for push subscriptions. -- https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-reinitsubscription-transact-sql?view=sql-server-2017 -- Execute at the Publisher to reinitialize the push subscription. --================================================================================================================================================ EXEC sp_reinitsubscription @publication = N'my_publication_Pub', @subscriber = N'my_subscriber', @destination_db = N'ORCA_Repl_Sub', --the destination database on the subscriber server @article ='one_or_all_of_the_articles' --you can specify the name of one article or put `all` for all articles GO --======================================================================== -- Start the Snapshot Agent job. --======================================================================== use [ORCASTG_CA18_Repl] EXEC sp_startpublication_snapshot @publication = N'my_publication_Pub', go