Restore Orphaned Users in MS SQL

1607
2
08-05-2016 05:12 AM
Labels (1)
SamQuon
New Contributor II
0 2 1,607

I ran into an issue with connecting to a geodatabase in MS SQL after restoring the database from a backup. The restore process created several orphaned users. I was able to identify the orphaned users using the following query in Microsoft Management Studio.

SELECT dp.type_desc, dp.SID, dp.name AS user_name 
FROM sys.database_principals AS dp
LEFT JOIN sys.server_principals AS sp 
     ON dp.SID = sp.SID
WHERE sp.SID IS NULL
     AND authentication_type_desc = 'INSTANCE'; 

This generated the list of users based on missing SQL Server authenticated logins.

Next I needed to map the orphaned user to the existing login with the following query in Microsoft Management Studio.

ALTER USER <user_name> WITH Login = <login_name>;

The source of the solution came from: https://msdn.microsoft.com/en-us/library/ms175475.aspx

Tags (2)
2 Comments
Labels