Search for Orphaned Users After a Database Restore

After a database has been restored, users may become orphaned, or disconnected, from the database. You will see an entry for the user in the syslogins table (select * from syslogins;), but the user will not be able to sign onto the restored database. You have to clear these with the sp_change_users_login stored procedure.

Check for user disconnects or orphaned users by using the following SQL script:

-- Search for orphans using the following user report
use [Database Name]
go
sp_change_users_login 'report'
go

Attach the orphaned users:

-- If there are orphans, clear them with the following script
sp_change_users_login 'update_one', 'User Name', 'User Name'
go

Leave a Reply