SQL SERVER: Error 1502- Error User Group or Role Already Exists in the Current Database

Error: "User, group, or role 'someuser' already exists in the current database. (Microsoft SQL Server, Error: 15023)".

The above error arises once I restore the database and try to log in on it. Sadly, it does not seem to be up to the task of fixing this issue using SQL Management Studio alone.

To fix this issue, you have to open a query window in SQL Server Management Studio and execute the following SQL query steps.

1- Get User Information

 If you have the information about the users, then you can skip this step. If not then use the following query.

USE DatabaseName
EXEC sp_change_users_login 'Report'

This query will return the result set of users.

2- Fix the issue one by one for the users

The following query will responsible for fixing the issue.

USE Database
EXEC sp_change_users_login 'Auto_Fix', 'user'


The row for user '****' 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.**

If you want to create a new user password then also you can use the above query as below.

USE Database
EXEC sp_change_users_login 'Auto_Fix', 'user', NULL, 'password'

No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Related Posts

Fatal Error: Peer authentication failed for user "postgres", when trying to get pgsql working with rails.

Problem: Sometimes, we get the following error when trying to make a connection in Rails.  FATAL ERROR: Peer authentication failed for us...