Solved

SQL User Mappings error

Posted on 2016-09-25
3
54 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

862 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now