MSSQL Replication 建立發行集發生 Error 50000

Ryan Chen
5 min readFeb 27, 2019

--

最近測試環境在做調整,本想要使用 AlwaysOn 做分流與備援管理,但因為是開發區,建立 AlwaysOn 覺得有點搞剛,之後便想說使用 Replication 來實作開發區備援就好,快又方便。

目標是建立點對點發行集,但是出師有點不利,在建立發行集時便發生錯誤。

原以為是剛好資料庫是在執行 Transaction 或是例行備份,造成資源衝突或 Lock 然後執行工作就被犧牲,除錯方向便從確認是否有其他執行中的交易開始,但在查閱執行中的工作後發現並沒有任何交易造成鎖定或衝突,接下來便去查看 SQL Log 確認詳細錯誤情況。

查看 SQL Log 發現是找不到網域帳號

Error 18456 帳號密碼錯誤,除錯方向開始朝向為何會找不到這個帳號,由於使用的是網域帳號進行代理,也確認已經加入登入以及 sysadmin 權限,在這裏有點卡關

接下來陰錯陽差的想到之前常遇到的一個問題:資料庫擁有者建立資料庫圖表的問題。就是 DB Owner 如果你是使用網域帳號登入進行建立或還原時,Owner 會是你的網域帳號,有時會發生當你要建立資料庫圖表或跑 Job Agent 時,會跟你說無法獲得此使用者資訊

Error: 15404, State: 19. Could not obtain information about Windows NT group/user ‘Domain\MyAccount’

通常遇到這問題網路上的解法都會跟你說把 Owner 改成 SA 就可以了,但是結合此次問題一併思考之後發現會不會是因為目前 SQL Engine 的服務帳號並沒有辦法查閱到 AD 的使用者,所以才會造成此問題發生,因此開始針對Error 15404 進行 Survey 與測試

SQL Error 15404 的 MSDN 文件中寫道:

15404 is used in authentication when an invalid principal is specified. Or, impersonation of a Windows account fails because there is no full trust relationship between the SQL Server service account and the domain of the Windows account.

解決方式是

Check that the Windows principal exists and is not misspelled.

If this error is the result of a lack of a full trust relationship between the SQL Server service account and the domain of the Windows account, one of the following actions can resolve the error:

- Use an account from the same domain as the Windows user for the SQL Server service.

- If SQL Server is using a machine account such as Network Service or Local System, the machine must be trusted by the domain containing the Windows User.

- Use a SQL Server account.

確認後依循 MSDN 的做法,將 SQL 服務帳號改成網域帳號,並且將網域帳號加入 BUILTIN\Windows Authorization Access Group 中,使其具有 AD 查閱的權限。

重新啟動服務並再次建立 Replication 發行集,這次便順利成功

連 DB Owner 造成無法建立資料庫圖表或執行 Job Agent 的問題也都一併解決了!

參考資料

--

--