Original: Error 21002:[SQL-DMO] user "xxx" already exists
Reprinted from: http://topic.csdn.net/u/20120829/09/faf381b6-d4e9-4f97-a21f-d1adfd43fbe4.html?seed=1190913404&r= 79566866#r_79566866
MSSQL2000 when you migrate a database or restore a database, create a new user name or specify a database logon user error message: "Error 21002:[SQL-DMO" user "xxx" already exists "
Cause:
This is what we often call "orphaned users", the so-called orphaned accounts, that is, the account of a database only the user name and no login, such users in the user library sysusers system tables exist, and in the master database syslogins there is no corresponding record.
orphaned accounts are typically produced in two ways:
1. Restore the backed-up database to another machine;
2. After reloading the system or SQL Server, only the user library is restored
Workaround:
The workaround is to use sp_change_users_login to fix it.
There are three ways to use sp_change_users_login
Repair Method:
Step 1:
Open Query Analyzer and run the following command into the corresponding database
exec sp_change_users_login ' report '
List orphaned users of the current database
Step 2:
exec sp_change_users_login ' auto_fix ', ' User name '
you can automatically add a login with the same name that corresponds to the user name to syslogins
Step 3:
exec sp_change_users_login ' update_one ', ' User name ', ' Login name '
maps the user name to the specified login name.
after running the above three commands, you can try again, the user will be able to log in normally
Error 21002:[SQL-DMO] user "xxx" already exists