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 Fix Error "Could not allocate space for object 'X' in database"?

Error Message Could not allocate space for object 'dbo.ABC_XYZ_XYZ'.'AB__ABC_XYZ__XYZ' in...

How to change port for MSSQL Server 2008?

In Windows VPS, 1533 is the default port for MSSQL Server. Following steps will guide you to...

How to Increase the MS SQL Remote Query Timeout?

MS SQL Server has an option called Remote Query Timeout to specify the time (in seconds), a...

How to fix an error "change password failed for login sa"?

Sometimes you receive following error while trying to reset MS SQL sa password via SQL Management...

How to fix "Upgrade Error - Valid Database compatibility level and successful connection rule"?

One of our Windows VPS customers wanted to upgrade SQL Server from SQL Server 2008 R2 to SQL...

  • 0 Users Found This Useful

Was this answer helpful?