When the database is restored from the backup file of another instance and users are added and mapped to the table, save the prompt that SQL Server Error 15023 user already exists. My solution:
EXECUTE sp_change_users_login ‘Update_one’,’login1′,’login1′
ALTER USER login1 WITH LOGIN = login1
Note that this is done on the corresponding DataBase (Use [DataBase]) and cannot be done on the Master or any other system DataBase
It is said that there is batch processing, not pro test, as follows:
1 -- fix all orphan users in database 2 -- where username=loginname 3 DECLARE @orphanuser varchar(50) 4 DECLARE Fix_orphan_user CURSOR FOR 5 SELECT dp.name As Orphan_Users 6 FROM sys.database_principals dp 7 left join sys.server_principals sp 8 ON dp.sid=sp.sid 9 WHERE sp.name IS NULL 10 AND dp.type='S' AND 11 dp.name NOT IN ('guest','INFORMATION_SCHEMA','sys') 12 13 OPEN Fix_orphan_user 14 FETCH NEXT FROM Fix_orphan_user 15 INTO @orphanuser WHILE @@FETCH_STATUS = 0 16 BEGIN 17 18 EXECUTE('ALTER USER ' + @orphanuser + ' WITH LOGIN = ' + @orphanuser) 19 20 FETCH NEXT FROM Fix_orphan_user 21 INTO @orphanuser 22 END 23 CLOSE Fix_orphan_user 24 DEALLOCATE Fix_orphan_user
References from the solution: http://www.sqlservergeeks.com/sql-server-error-15023-user-already-exists-in-current-database/
Reproduced in: https://www.cnblogs.com/hu123rong00/p/7116496.html
Read More:
- Solution to SQL Server Error: 4064
- SQL Server “login failed for user ‘domain account”. [sqlstate 28000] (error 18456). “Problem solving
- Modifying SVN user name and password in eclipse
- SQL Server 2008 login 4064 error solution
- New user’s shell, delete prompt ^ H, up and down prompt ^ A ^ B, tab key is useless
- Solution of error converting data type varchar to datetime in SQL Server
- SQL server error 15404 solution
- Install sql2012 prompt setup account privileges failed solution
- SQL Server 2008 18456 error and SA unable to login solution
- Browser prompt: Source mapping error: request failed with status 404 Source URL: http://xxx.js Source mapping URL: jquery.min.map
- Add samba user prompt Failed to add entry for user.
- [Linux] solution: SCP different server copy file prompt permission denied, please try again
- Add Samba user prompt failed to add entry for user
- Microsoft SQL server, additional database error: error 916 solution
- [resolved] superset failed to create admin user: error! User already exists user or attributeerror: ‘nonetype’‘
- SQL server remote computer refused network connection, error: 1225, specific solution steps.
- The solution of PL / SQL can’t connect to the remote server after installing Oracle locally
- MS SQL Could not obtain information about Windows NT group/user ‘domain\login’, error code 0x5. [SQ…
- SQL 2005 remote connection error (provider: SQL network interface, error: 28 – the server does not support the requested protocol
- [solved] sql30082n security processing failed with reason “24” (“user name and / or password invalid”)