Update database user name to another login name
Why?
Error: 18456, followed by
Error: Login failed for user 'username'. Reason: Failed to open the explicitly specified database.
and then you find out that in your database, there is a user name that has no login name
How to fix it?
you can use sp_change_users_login to update database user name to another login name and usually used to fix orphaned user name (user name without login name), but only for SQL Server login and this is executed on database level.
sp_change_users_login ‘Report’ : search all user names that have no login name
sp_change_users_login ‘update_one’, ‘user name’, ‘login name’ : update the user name.
if you want to update orphaned user name for windows login name, you can drop the orphaned user name in your database, create the login name and then add it to your database again. (^.^)v