After a database migration, the new SQL Server Client tool sets the association, often with an error:
User, group, or role ' XXX ' already exists in the current database.
Workaround:
First introduce the difference between "login" and "User" in SQL Server, "login" is used for user authentication, and the database "user" account is used for database access and permission validation. The login is associated with the user through a security identifier (SID).
When you restore a database to a different server, the database contains a set of users and permissions, but at this point the database server does not have a login associated with this set of users. This situation is known as "orphaned users". Logon issues cannot be resolved either by creating a new login or by granting the user permission to the corresponding database for a login with the same name because SQL Server reported "error 15023: User or role already exists in the current database."
To solve this problem, you need to call the system stored procedure sp_change_users_login, as follows:
Use database name
Go
Sp_change_users_login ' Update_One ', ' Database user name ', ' Login name '
SQL Server client logins are associated with database users