Database Research & Development

  • Home
  • NoSQL
    • NoSQL
    • Cassandra
  • Databases
    • Database Theory
    • Database Designing
    • SQL Server Coding Standards
    • SQL Server
    • PostgreSQL
    • MySQL
    • Greenplum
    • Linux
  • Interviews
    • SQL Server Interviews
    • MySQL Interviews
    • SQL Puzzles
  • DBA Scripts
    • SQL Server DBA Scripts
    • PostgreSQL DBA Scripts
    • MySQL DBA Scripts
    • Greenplum DBA Scripts
  • Home
  • Blog Archives !
  • (: Laugh@dbrnd :)
  • Contact Me !
sqlserverinterviews
Home 2016 November SQL Server: Error 15023 User already exists in current database (Problem of Orphan User)

SQL Server: Error 15023 User already exists in current database (Problem of Orphan User)

This article is half-done without your Comment! *** Please share your thoughts via Comment ***

In this post, I am going to share one of the common error which is faced by most of the SQL Server DBA when they are migrating database from one server to another server.

Error 15023: User already exists in the current database. This basically the problem of Orphan users, which exists as a Database Login, but no longer exists in Master Database.

For example, I have migrated one database and user “dbrnd” exists in that database. In that new server, now I am going to create “dbrnd” login with assignment of that database.
Which threw an error like user already exists in the current database.

The simple solution is to map SID between Database login and Master Login.
Step 1: Identified orphaned users of your restored database.

1
2
3
4
5
6
7
8
9
SELECT
[dp].[type_desc]
,[dp].[SID]
,[dp].[name] AS UserName
FROM sys.database_principals AS dp
LEFT JOIN sys.server_principals AS sp
ON [dp].[SID] = [sp].[SID]
WHERE [sp].[SID] IS NULL
AND [dp].[authentication_type_desc] = 'INSTANCE';

Step 2: Select any of that SID and try to find in sys.sql_logins table. If you do not find any match record, that user is orphaned.

1
2
SELECT [sid]
FROM sys.sql_logins;

Step 3: Create manual login and map your missing SIDs:

1
2
3
CREATE LOGIN Login4Orphaned
WITH PASSWORD = 'test123*1',
SID = 0x088232135A0AAF44A2D1B18DCC280E44;

Step 4: Now, create user for this and a make your orphaned user as specific user:

1
ALTER USER MyUser123 WITH Login = Login4Orphaned;

Nov 12, 2016Anvesh Patel
SQL Server: How to configure and enable Microsoft Distributed Transaction Coordinator (MSDTC)?SQL Server: Error Msg 5009-One or more files listed in the statement could not be found or could not be initialized
Anvesh Patel
Anvesh Patel

Database Engineer

November 12, 2016 SQL ServerAnvesh Patel, database, database research and development, dbrnd, login, map sid, orphan user, SID, SQL Query, SQL Server, SQL Server Administrator, SQL Server Monitoring, SQL Server Performance Tunning, SQL Server Tips and Tricks, TSQL
About Me!

I'm Anvesh Patel, a Database Engineer certified by Oracle and IBM. I'm working as a Database Architect, Database Optimizer, Database Administrator, Database Developer. Providing the best articles and solutions for different problems in the best manner through my blogs is my passion. I have more than six years of experience with various RDBMS products like MSSQL Server, PostgreSQL, MySQL, Greenplum and currently learning and doing research on BIGData and NoSQL technology. -- Hyderabad, India.

About DBRND !

dbrnd

This is a personal blog (www.dbrnd.com).

Any views or opinions represented in this blog are personal and belong solely to the blog owner and do not represent those of people, institutions or organizations that the owner may or may not be associated with in professional or personal capacity, unless explicitly stated.

Feel free to challenge me, disagree with me, or tell me I’m completely nuts in the comments section of each blog entry, but I reserve the right to delete any comment for any reason whatsoever (abusive, profane, rude, or anonymous comments) - so keep it polite.

The content of this website is protected by copyright. No portion of this website may be copied or replicated in any form without the written consent of the website owner.

Recent Comments !
  • Anvesh Patel { Sure will do... } – May 27, 12:43 PM
  • Anvesh Patel { Great... } – May 27, 12:41 PM
  • Anvesh Patel { Great... } – May 27, 12:39 PM
  • Anvesh Patel { Great... } – May 27, 12:36 PM
  • Anvesh Patel { Great... } – May 27, 12:28 PM
  • Anvesh Patel { Great... } – May 27, 12:27 PM
  • Anvesh Patel { Great... } – May 27, 12:16 PM
  • Older »
Follow Me !
  • facebook
  • linkedin
  • twitter
  • youtube
  • google
  • flickr
© 2015 – 2019 All rights reserved. Database Research & Development (dbrnd.com)
Posting....