User, group, or role already exists in the current database.

 

當發生此錯誤訊息時

「User, group, or role already exists in the current database.」

 

原因在於原本的 database 就已經存在 'myName' 的使用者了,

 

但現在卻要將一個 'myName' 使用者的 User Mapping

再次地指向 testDB 裡的 'myName' 使用者

 

當然會發生「User, group, or role already exists in the current database.」錯誤囉。

 

解決辦法有二

1、下指令

USE testDB

EXEC sp_change_users_login 'Auto_Fix', 'myName'

 

2、刪掉使用者再重新加入

a、先將 testDB 裡的 'myName' 使用者拿掉

 

b、再將 'myName' 使用者的 User Mapping,再次地指向 testDB。

成功後,此時 testDB 會自動生成 'myName' 使用者