Solved

SQL User Mappings error

Posted on 2016-09-25
3
79 Views
Last Modified: 2016-09-25
After copying a database and security information to a new server, I'm trying to map a user ('UserX') to a database in SQL.  However, when attempting to save, I get an error message: User, group, or role 'UserX' already exists in the current database.  UserX does exist in the database.  I tried to delete the user in the database, but the user is tied to a database schema.  Attempting to delete the schema...already a likely bad idea...fails tied to an object named 'admins'.  How can I get 'UserX' mapped to the database?  What needs to be undone and reconstructed?

Thanks in advance.
0
Comment
Question by:DaneBigham
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 34

Accepted Solution

by:
ste5an earned 500 total points
ID: 41814631
Take a look at the system procedure sp_change_users_login.

List unmapped users:
EXECUTE sp_change_users_login 'report';

Open in new window


Repair a user:
EXECUTE sp_change_users_login 'update_one', 'username', 'loginname';

Open in new window


Where username is the name of your UserX and loginname is the name of an existing login, which the user should be mapped to.

btw, when this error occurs in SSMS dialog, this can happen. In such a case use T-SQL (CREATE LOGIN and CREATE USER FOR LOGIN).
0
 
LVL 78

Expert Comment

by:arnold
ID: 41814709
The issue as was pointed out is two fold.
1) the database backup includes the security settings for the database which includes the SID of the users, groups; however
2) the sql server security is where the logins are actually stored.

when migrating databases from one server to another, creating a user requires the use and setting  of the SID to match the one in the database. MS provides an SP that deals with listing the users/password/sids on the original server with a create user directive that can be copied and used to create the user on the new system.

Here is the link to the MS SP..
https://support.microsoft.com/en-us/kb/918992
0
 

Author Closing Comment

by:DaneBigham
ID: 41814824
This worked perfectly.  Thanks!
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question