Monday 25 May 2015

SQL Server, Error: 15023, User, group, or role already exists in the current database.

Once we restore database there might be a problem with given message, related with users and role, once you are going to mapping database with user.

To solve this problem in SQL Server 2008 or R2
select database_name

see how many users are there in database
EXEC sp_change_users_login 'Report'

--auto fix db users
EXEC sp_change_users_login 'Auto_Fix', 'user_name'

You will get following message

The row for user 'xxxx' will be fixed by updating its login link to a login already in existence.
The number of orphaned users fixed by updating users was 1.
The number of orphaned users fixed by adding new logins and then updating users was 0.

Now you can check in your user > mapping all will well :)