User, Group, or Role already exists in the current database. (Microsoft SQL Server, Error: 15023)
While after restoring the database I just created the users in the new server and then trying to map to the restored databases …. I got an error like User, Group, or Role already exists in the current database… 🙁
This error 15023 occurs in current database when a database is restored from another sql instance
The databse user is not mapped to the corresponding login at the instance where it is restored and termed as orphaned user.
So when I tried to login to the restored database with an orphan user it gives error as “login failed for ‘user1”.
To resolve this issue . Execute the following stored procedure to bind the user mappings from the old server to the new server.
use [database_name] exec sp_change_users_login 'AUTO_FIX', '[user_name]' go
Now you can check in user Login Properties and you will see that old user mappings are restored in your new SQL Server.
You will get following output if it’s successful
The row for user 'user1' 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
This error was found in sql server 2012 express and above is the solution for it. Please comment if you find the post useful.
You may also like: Solution: sudo /usr/bin/sudo must be owned by uid 0 and have the setuid bit set