如何:檢視和修改發行者和散發者屬性 (複寫 Transact-SQL 程式設計)

您可以使用複寫預存程序來以程式設計的方式檢視發行者和散發者屬性。

檢視散發者和散發資料庫屬性

  1. 執行 sp_helpdistributor,傳回有關散發者、散發資料庫和工作目錄的資訊。

  2. 執行 sp_helpdistributiondb,傳回指定之散發資料庫的屬性。

變更散發者和散發資料庫屬性

  1. 在散發者上,執行 sp_changedistributor_property 來修改散發者屬性。

  2. 在散發者上,執行 sp_changedistributiondb 來修改散發資料庫屬性。

  3. 在散發者上,執行 sp_changedistributor_password 來變更散發者密碼。

    安全性注意事項安全性注意事項

    可能的話,會在執行階段提示使用者輸入其認證。請避免將認證儲存在指令碼檔案中。

  4. 在散發者上,執行 sp_changedistpublisher 來變更使用此散發者之發行者的屬性。

範例

下列範例的 Transact-SQL 指令碼會傳回有關散發者和散發資料庫的資訊。

-- View information about the Distributor, distribution database, 
-- working directory, and SQL Server Agent user account. 
USE master
EXEC sp_helpdistributor;
GO
-- View information about the specified distribution database. 
USE distribution
EXEC sp_helpdistributiondb;
GO

此範例會變更散發者的保留期限、連接散發者所使用的密碼,以及散發者檢查各種複寫代理程式之狀態的間隔 (也稱為活動訊號間隔)。

安全性注意事項安全性注意事項

可能的話,會在執行階段提示使用者輸入安全性認證。如果您必須將認證儲存在指令碼檔案中,則必須維護這個檔案的安全性,使他人無法在未獲授權的情況下擅自存取。

-- Change the heartbeat interval at the Distributor to 5 minutes. 
USE master 
exec sp_changedistributor_property 
    @property = N'heartbeat_interval', 
    @value = 5;
GO
DECLARE @distributionDB AS sysname;
SET @distributionDB = N'distribution';

-- Change the history retention period to 24 hours and the
-- maximum retention period to 48 hours.  
USE distribution
EXEC sp_changedistributiondb @distributionDB, N'history_retention', 24
EXEC sp_changedistributiondb @distributionDB, N'max_distretention', 48
GO 
-- Change the password on the Distributor. 
-- To avoid storing the 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".
USE master
EXEC sp_changedistributor_password $(Password)
GO