How to identify and fix the orphan users in MSSQL Server?

Orphaned user in MSSQL means that a user who is present at the database level but the relevant login doesn’t present on the server. This kind of user can be created when you perform database migration. 

By default, MSSQL Server login is mapped with SQL Database user. If this is not defined properly for MSSQL Server principal then the user will not be able to log in successfully for its database and this user is called an orphan user.

Please find the below SQL query to find the orphaned users in MSSQL.

USE
USER DATABASE
EXEC SP_CHANGE_USERS_LOGIN ‘REPORT’
GO

The following are the steps to fix orphaned users using ORPHANED USER SID

If there are any orphaned users, then we can create its login by using orphaned user SID.

Syntax:

USE
MASTER
CREATE LOGIN [LoginName] WITH PASSWORD = ‘[email protected]’,
SID = 0xF0C10D1C8EDFGA06435B07DAD54FFAE

Related Articles

How to shrink MSSQL Database?

Important Note: We don't recommend to shrink your database. You can involve your Database...

How to Backup MSSQL Database from SQL Server Management Studio?

To take MS SQL database backup, first you need to connect to MS SQL Server through SQL Server...

How to configure MSSQL server default language configuration option?

Recently, we faced strange issue wherein one of our customers was capturing error messages coming...

How do I connect to MSSQL Server 2012 from SQL Server Management Studio?

This article will guide you on how to connect to MS SQL Server 2012 from SQL Server Management...

How to change password for MS SQL admin user?

Following tutorial will guide you to reset the MS SQL server sa user password. We assume that you...

  • 0 Users Found This Useful

Was this answer helpful?