Technical Article

Very easy way to fix ORPHAN users

,

Run this script against the database restored from other SQL Server database. It will solve the orphan users.

declare @usrname varchar(100), @command varchar(100)

declare Crs insensitive cursor for

  select name as UserName from sysusers
  where issqluser = 1 and (sid is not null and sid <> 0x0)
                    and suser_sname(sid) is null
  order by name

for read only

open Crs

fetch next from Crs into @usrname
while @@fetch_status=0

begin

  select @command=' sp_change_users_login  ''auto_fix'', '''+@usrname+''' '

  exec(@command)

  fetch next from Crs into @usrname

end

close Crs

deallocate Crs

Rate

4 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

4 (1)

You rated this post out of 5. Change rating