Wednesday, January 22, 2014

Fix Orphan Users After Backup / Restore Databases Across Servers

Sometimes when backup database from one server and restore it to another server for the purposes like migrating or moving database from production server to testing or vice versa, you probably face a problem that a login can't access that database even if you find that login in the Security/ Users folder of the database. This is because when you restore a database to another server the users became unmapped to any login, and you will find nothing in the "Login name" in the user property:

instead of something like:

Fixing this is simple you need to run:

EXEC sp_change_users_login 'Auto_Fix', [user]

for example and to fix the case in the above figures:

EXEC sp_change_users_login 'Auto_Fix', 'privuser'

Also the following is another way to fix it:

ALTER USER [theUsername] WITH LOGIN [theUsername] 

No comments:

Post a Comment