Solved

SQL User Mappings error

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

Accepted Solution

by:
Stefan Hoffmann earned 500 total points
Comment Utility
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 76

Expert Comment

by:arnold
Comment Utility
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
Comment Utility
This worked perfectly.  Thanks!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function

771 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

11 Experts available now in Live!

Get 1:1 Help Now