User already exists in current database SQL Server 2005 Error 15023
Posted
Monday, January 14, 2008 2:43 PM
by
Nathan Zaugg
I posted a blog entry a while back about how to change the owner of a database. What that still does not solve is the problem you have when there is a database user in the database you restored and there is a database user already in your system, each with the same name. While it seems intuitive that it should just work, it doesn't! The user in the database is essentially an orphan.
To find such orphans in your newly-restored database we run this command:
EXEC sp_change_users_login 'Report'
This simply gives us a list of these orphan logins. Generally you want to map the two users back to each other and we can do that with this command:
EXEC sp_change_users_login 'update_one', 'WebUser', 'WebUser'
You can run the first command again to see if it worked. In my case I had to try to login a couple of times before the I could get it to login. If that fails to work there is another, more powerful command you can run:
EXEC sp_change_users_login 'Auto_Fix', 'WebUser', NULL, 'MyWebUserPassword'
If you are too lazy to even do that, there are a few stored procedures on this blog entry that you can try running:
I hope this helps someone besides just me! Drop me a line if this blog entry was useful.