User Already Exists in the Current Database - SQL Server

Posted by bullpit on Geeks with Blogs See other posts from Geeks with Blogs or by bullpit
Published on Wed, 21 Apr 2010 12:59:19 GMT Indexed on 2010/04/21 13:03 UTC
Read the original article Hit count: 231

Filed under:

I was moving a lot of databases from one SQL Server to another, and my applications were giving me errors saying "Login failed for <user>". The user was already in the database with appropriate rights to allowed objects in the database. I tried mapping the user to the database and that's when I got this message:

"User Already Exists in the Current Database"...

I googled and found this very useful post about orphaned users when moving databases.

These are the steps you should take to fix this issue:

First, make sure that this is the problem. This will lists the orphaned users:
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'

© Geeks with Blogs or respective owner