Solved

SQL User Mappings error

Posted on 2016-09-25
3
70 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
3 Comments
 
LVL 33

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 77

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

856 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