Sql-Server

為什麼我的交易沒有被複製?交易序列號是多少?

  • April 11, 2017

根據下圖,我一直在對複制問題進行故障排除:

複製問題

參考上圖,

我可以使用以下查詢獲得分發代理會話的位 :

--================================================================================
-- finally the contents 
-- sessions of the distribution agent:
--================================================================================
use [master]
exec [distribution]..sp_MSenum_distribution_s 
@name = N'MYSERVER-Product-Product-MYSUBSCRIPTION-184', 
@hours = -1, 
@session_type = 1

所選會話中的操作

--========================================================
-- get the actions in the selected session:
-- for each row on the above data, we can get the details:
--========================================================
-- example of the last session - without errors
use [master]
exec [distribution]..sp_MSenum_distribution_sd 
@name = N'MYSERVER-Product-Product-MYSUBSCRIPTION-184', 
@time = N'20170411 14:16:03.920'

在此處輸入圖像描述

-- example of the second session - with errors
use [master]
exec [distribution]..sp_MSenum_distribution_sd 
@name = N'MYSERVER-Product-Product-MYSUBSCRIPTION-184', 
@time = N'20170410 15:50:27.650'

在此處輸入圖像描述

現在下面的這段程式碼給了我我正在尋找的錯誤:

所選會話的錯誤詳細資訊或消息:

問題也在這裡:

如何從上面的結果中獲取數字5468694並在下面的查詢中使用它?

--========================================================================
-- Error details or message of the solected session:
--=========================================================================
   use [master]
   exec [distribution]..sp_MSenum_distribution_sd 
   @name = N'SQLAPPLON1-Product-Product-REPLON1-184', 
   @time = N'20170410 15:50:27.650'

   use [master]
   exec [distribution]..sp_MSget_repl_error 
   @id = 5468694

在此處輸入圖像描述

這不是一個經過驗證的查詢,因為我沒有執行複制,但是在為兩者sp_MSenum_distribution_sdsp_MSget_repl_errorvia編寫定義腳本sp_helptext並將底層邏輯粉碎在一起之後,我想出了以下內容,可能會給你你正在尋找的東西。

DECLARE @name NVARCHAR(100), @time DATETIME

SET @name = N'SQLAPPLON1-Product-Product-REPLON1-184', 
   @time = N'20170410 15:50:27.650'

SELECT  msre.source_type_id, 
       msre.source_name, 
       msre.error_code,    
       msre.error_text, 
       sys.fn_replformatdatetime(msre.time) AS 'time',
       error_type_id, 
       CASE WHEN msre.xact_seqno IS NULL OR msre.xact_seqno = 0x0
           THEN CONVERT(BIT, 0) ELSE CONVERT(BIT, 1) END AS has_xact_seqno,
       msre.xact_seqno, 
       msre.command_id,
       rh.error_id
FROM    [distribution].dbo.MSrepl_errors msre 
       INNER JOIN [distribution].dbo.MSlogreader_history rh WITH (READPAST)
           ON msre.id = rh.error_id
WHERE   rh.agent_id = (SELECT TOP 1 ID 
                      FROM MSlogreader_agents 
                      WHERE name = @name)
       AND rh.start_time = @time 
       AND rh.comments not like N'<stats state%'
       AND rh.error_id <> 0
       -- rows with error_type_id are placeholders
       AND msre.error_type_id IS NOT NULL
ORDER BY 5 ASC

引用自:https://dba.stackexchange.com/questions/170722