Fixing orphaned SQL Server users
If you transfer a SQL Server database from one machine to another then you’re pretty much guaranteed to break any users associated with it. This is because the IDs for the linked logins are unique to each machine.
There is, however, a handy stored procedure that can help you restore the orphaned user: sp_change_users_login.
All you need to do is run the following command against the database in question, substituting [user_name] for the name of the user you want to restore:
exec sp_change_users_login 'auto_fix', '[user_name]';
