This issue occurs on the migration value of the database. After moving the value, the database login name and database user name are orphaned, the original data, with the established user name password login can access the database, but the value will not be accessed after the move. And if you try to grant database access to the login, the following error message occurs because the user already exists: ' The login already has an account under another user's name '.
The cause of the error is:
After you transfer the login account and password to the destination server, your users may not have access to the database. The login account is associated with the user by a security identifier (SID), and when you move the database, SQL Server may deny the user access to the database if the SID is inconsistent. This issue is known as orphaned users. Orphaned users can be generated if you use the SQL Server for DTS transport logon feature to transfer logins and passwords. Additionally, an integrated login account that is allowed access to a target server that is in a different domain from the source server can also cause orphaned users to appear.
Here are the workarounds:
1. Find orphaned users. Open Query Analyzer on the destination server, and then run the following code in the user database that you moved: Exec sp_change_users_login ' report ', find to execute after
Use lk96160
Go
Sp_change_users_login ' Update_One ', ' lk96160 ', ' lk96160 '
The general problem will be solved.
2. If a user is an orphaned user, the database user can successfully log on to the server but does not have access to the database. If you try to grant database access to the logon account, the following error message occurs because the user already exists:
Microsoft SQL-DMO (ODBC sqlstate:42000) Error 15023:user or role '%s ' already exists The current database.
or the login name should be changed to dbo for the user, then execute the following code under SA:
exec sp_changedbowner ' sa '
And then do it again:
Use lk96160
Go
Sp_change_users_login ' Update_One ', ' lk96160 ', ' lk96160 '
The general problem will be solved.
Orphaned users in SQL Server