[SQL Server] SQL DB移植時,無法授權使用者

各位在使用SQL Server做資料庫轉移還原時,有時候可能會發現原本授權的帳號無法登入使用資料庫(假設原本資料庫上的使用者為admin,而新移植的資料庫使用者也叫做admin,但是移植過去後,無論怎麼授權admin給這個資料庫,都會出現無法授權的情況)。這是因為資料庫的使用者SID不一致所導致的。

此時,只要到這個資料庫,執行兩個步驟:

1. 執行指令:EXEC sp_change_users_login ‘report’;

找出有哪些孤兒使用者(orphaned users)?

2. 執行指令: EXEC sp_change_users_login ‘Auto_Fix’, ‘找到的使用者名稱’;

如此一來就搞定了。

參考資料

  1. SQL 資料庫還原到到另一台後無法登入要怎麼解決
  2. Using sp_change_users_login to fix SQL Server orphaned users
This entry was posted in SQL Server, 資工. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *