[SQL SERVER][HA]grant endpoint permission
今天參考自己以前文章建立DB Mirroring ,但我在主體上設定鏡像夥伴總是失敗(出現找不到 standby DB),
這時我去 standby db 看log出現以下內容
訊息寫得很清出,SQLUser沒有連接endpoint權限,所以在主體上執行授權後終於搞定。
grant connect on endpoint::Mirroring to [.\SQLUser]
主體
standby
補充: connectionstring 增加Failover Partner=MirrorServerAddress,但Failover後發現AP無法登入MirrorDB,
這主要是因為Login SID不同所導致,所以在建立login時,不只帳號密碼需相同、SID也需要相同
Login failures connecting to new principal after SQL Server Database Mirroring failover
SELECT
'create login [' + p.name + '] ' +
case when p.type in('U','G') then 'from windows ' else '' end +
'with ' +
case when p.type = 'S' then 'password = ' + master.sys.fn_varbintohexstr(l.password_hash) + ' hashed, ' +
'sid = ' + master.sys.fn_varbintohexstr(l.sid) +
', check_expiration = ' + case when l.is_expiration_checked > 0 then 'ON, ' else 'OFF, ' end +
'check_policy = ' + case when l.is_policy_checked > 0 then 'ON, ' else 'OFF, ' end +
case when l.credential_id > 0 then 'credential = ' + c.name + ', ' else '' end
else '' end +
'default_database = ' + p.default_database_name +
case when len(p.default_language_name) > 0 then ', default_language = ' + p.default_language_name else '' end
FROM sys.server_principals p
LEFT JOIN sys.sql_logins l ON p.principal_id = l.principal_id
LEFT JOIN sys.credentials c ON l.credential_id = c.credential_id
WHERE p.type in('S','U','G')
AND p.name <> 'sa'