How to resolve orphaned users in SQL Server

I recently got to duplicate / migrate a SQL Server 2008 database.

I had trouble with the logins, which were broken after the move. It has to do with mismatching SID for DB users.

To fix, one needs to select the database in question then

exec sp_change_users_login 'Report'

The procedure lists any orphaned users who do not link to a logon. Then, execute the following for each orphaned user

sp_change_users_login 'update_one', 'connection_user_name', 'db_user_name'

Source: How to move databases between computers that are running SQL Server
Source: Troubleshooting Orphaned Users

Page top