posts - 31, comments - 88, trackbacks - 0

My Links

News

Archives

Post Categories

Wednesday, April 21, 2010

User Already Exists in the Current Database - SQL Server

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'

Posted On Wednesday, April 21, 2010 7:59 AM | Feedback (0) | Filed Under [ SQL Server ]

Powered by: