STG Forums Index STG Forums
Seattle Technology Group Customer Discussion Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

SQL login problems after a backup/restore

 
Post new topic   Reply to topic    STG Forums Index -> IT (Technical Topics)
View previous topic :: View next topic  
Author Message
Mike Barskey



Joined: 10 Jul 2003
Posts: 124
Location: Seattle Technology Group, Inc. (Palm Springs office)

PostPosted: Fri Apr 02, 2004 9:32 am    Post subject: SQL login problems after a backup/restore Reply with quote

After doing a database backup and restore, you might encounter a problem where you cannot assign a user to a role or to the database, seeing an error such as:
"Error 15023: User or role '%s' already exist in the database"

To fix this problem, run the following SQL commands:
Code:
Exec sp_change_users_login @Action = 'Auto_Fix', @UserNamePattern = 'tsmith'


Note that you will need to enter the command "use CP" (or "CP2002," or whaterver your DB is called) before the line above if you are executing these SQL commands from OSQL or Query Analyzer, or any environment other that CP's Interactive SQL Wizard.

After the users are "fixed" then you need to assign them to their roles.

Here is an explanation of what has happened to cause this error. When you restored the databases to the second server, the users in them remained intact. However, the users are pointing to logins that do not exist or exist, but have different SIDs. Thus the users in the databases are "inconsistent" or "orphaned" and are not visible except if you query directly the sysusers table.

SQL Server offers a nice stored procedure, which resolves this problem - sp_change_users_login. What it basically does is if the login already exists, the user is modified in the sysusers table to match the right SID. If the login does not exist, it is created automatically and appropriate rights to the database are granted.

- Mike
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Mike Barskey



Joined: 10 Jul 2003
Posts: 124
Location: Seattle Technology Group, Inc. (Palm Springs office)

PostPosted: Fri Jul 09, 2004 10:51 am    Post subject: Password problems after fixing users Reply with quote

I have seen situations where fixing the login does indeed allow the user to login to SQL Server again, but it has reset their password to Null. In such a case, you will also need to issue a one-line command to update their password.

For detailed instructions, see the thread called "Changing users' passwords" in the the "IT (Technical Topics)" forum.

- Mike


Last edited by Mike Barskey on Wed Apr 11, 2007 8:02 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
nbecker



Joined: 09 Aug 2003
Posts: 27
Location: Seattle, WA

PostPosted: Wed Jan 12, 2005 12:20 pm    Post subject: Second Solution Reply with quote

Another solution to the above issue is to delete all the users from the users tree using Enterprise Manager for MS-SQL. Once you have deleted all user you then need to run the CPSQLUserMngUtil.exe utility that STG provides. You should notice that all the user will be added to the database without errors. Login to CP with a few different users to ensure this fixed the problem.
_________________
--------------------------
Noah Becker
(206) 324-4492 x5

--------------------------
Back to top
View user's profile Send private message AIM Address
Ryan
Site Admin


Joined: 29 Oct 2002
Posts: 63

PostPosted: Fri Jun 17, 2005 8:12 am    Post subject: Reply with quote

I've had a situation where the customer had multiple DBs on the SQL Server. We tried deleting all users from all roles in all databases. The SQL User Manager continued to fail (with message "user is already in the database"). We determined that the users were in the "public" role. Enterprise Manager would not allow deleting these users (it was greyed out). So...we backuped up the database, restored it on my computer, deleted the logins, backup it up, and restored it on the server. Worked fine. I'm not sure whether it is necessary to delete all of the DBs or not. We did and it was successful. Perhaps it would have failed if we did not.
Back to top
View user's profile Send private message
Mike Barskey



Joined: 10 Jul 2003
Posts: 124
Location: Seattle Technology Group, Inc. (Palm Springs office)

PostPosted: Fri Feb 16, 2007 4:52 pm    Post subject: Another way to fix user/login problems Reply with quote

Thanks to Alex at Carnegie Mellon University for finding these helpful Microsoft KnowledgeBase articles:

- Mike
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    STG Forums Index -> IT (Technical Topics) All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2002 phpBB Group