06 October 2010

SQL Server Error 15023: 'User already exists in current database'

I received this error when copying a database from one server to another and then tried to bring up a web application.  The system user that came over with the database was orphaned from the existing login.

The solution is relatively easy (for one login).  Use the sp_change_users_login with the 'update_one' option.  This will directly map the user to the SQL login.


exec sp_change_users_login 'update_one', '[your database user]', '[the SQL login]'


Thanks to Pinal Dave's article on this subject.