Tuesday, September 14, 2010

How to fix orphaned SQL Server users

A database user for which the corresponding SQL Server login is undefined or is incorrectly defined on a server instance cannot log in to the instance. Such a user is said to be an orphaned user of the database on that server instance. There are three possible ways to make a user orphaned

• Explicitly drop the login that user belongs to
• Restore database on another instance of sql server.
• Restore of an old master backup


Use database admin privilage account for resolving this issue.Find out the list of orphaned users for the database using below SP:

EXEC sp_change_users_login 'Report'

If you already have a login id and password for this user, fix it by doing:

EXEC sp_change_users_login 'Auto_Fix', 'user'

If you want to create a new login id and password for this user, fix it by doing:

EXEC sp_change_users_login 'Auto_Fix', 'user', 'login', 'password'

As per BOL ,Avoid using Auto_Fix in security-sensitive situations. Auto_Fix makes best estimates on links, possibly allowing a user more access permissions than intended. You can use Update_One which Links the specified user in the current database to login. login must already exist. user and login must be specified.

EXEC sp_change_users_login 'update_one', ‘UserName’,'LoginName'

1 comment: