March 20, 2017 at 6:09 pm
Comments posted to this topic are about the item Fix Orphan Users for All databases
March 20, 2017 at 8:20 pm
i think that resetting the database user(s) to match the login is the backwards way to do it; you have to re-do it with every restore.
i prefer to script out the user from , say production via sp_help_revlogin or something similar, so you have the sid, and drop and recreate the sql login on dev, then change the password on dev.
then the sids ALWAYS match, forever, and tno subsequent restores form production suffer from orphans any more.
Lowell
April 19, 2017 at 9:29 am
We have a test server where we restore a database and adjust the name adding the date to identify the version. Each time we do this we need to set the User from the database to the Server login. This seemed like a good solution for us. However running the code is giving me an error:
Msg 102, Level 15, State 1, Line 28
Incorrect syntax near '..sysusers su
JOIN sys.server_principals sp ON sp.name = su.name
WHERE issqluser = 1 AND
(su.sid IS NOT NULL AND su.sid <> 0x0'.
The code in question starts with: FROM '+quotename(@DatabaseName)+'..sysusers su
I am unsure where to go from here. Suggestions?
April 19, 2017 at 9:39 am
I blogged an alternative method of unorphaning SQL Server users a few years ago, when I was having to do this process every month or so. Fun times.
Thomas Rushton
blog: https://thelonedba.wordpress.com
April 19, 2017 at 11:41 am
Thank you for the information. I like the code and am going to test, however when I run the EXEC sp_change_users_login 'Report' on a database with several users, connected to a login or not, it doesn't return any records. I ran the code on master and several different databases (SQL 2014 and SQL 2016) all with Users. This is so simple I can't imagine what I am missing but obviously I am .
April 19, 2017 at 12:55 pm
Therese Hutcheson - Wednesday, April 19, 2017 11:41 AMThank you for the information. I like the code and am going to test, however when I run the EXEC sp_change_users_login 'Report' on a database with several users, connected to a login or not, it doesn't return any records. I ran the code on master and several different databases (SQL 2014 and SQL 2016) all with Users. This is so simple I can't imagine what I am missing but obviously I am .
sp_change_users_login 'Report' will only report on orphaned users - one where the SID in the database's sys.users table doesn't match the SID in the server's master.sys.logins table. (This is from memory - might not have the table names quite right here...) See https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-change-users-login-transact-sql for more.
Thomas Rushton
blog: https://thelonedba.wordpress.com
April 19, 2017 at 2:06 pm
I really appreciate your help.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply