SQL Server Error: 15023

Source: Internet
Author: User

SQL Server Error 15023: User or role already exists in the current database

Error: "Error 15023: User or role already exists in the current database" when a database backup on the remote server is restored to the local machine, and a "login" is associated with a "user" (user mapping).

  Reason:

The difference between "Log on" and "User" in SQL Server, "Log on" is used for user authentication, and the database "user" account is used for database access and permission validation. Logins are associated with the user through a security identifier (SID). When you restore a database to another server, the database contains a set of users and permissions, but there may not be a corresponding login or the user associated with the login may not be the same user. This situation is known as "orphaned users." You cannot resolve a logon issue by creating a new login or by granting the user permission for the corresponding database to a login with the same name because SQL Server reports "error 15023: User or role already exists in the current database"

  Solve:

To solve this problem, you need to invoke the system stored procedure sp_change_users_login, as follows:

Use Northwind

Go

Sp_change_users_login ' Update_One ', ' Test ', ' test '

Where Northwind is a database of orphaned users, Update_One is the parameter of the stored procedure, indicating that only one user is processed, the first test is "user", and the last Test is "login", and the above SQL indicates that the server is logged in "Test" and Northwind The database user "test" is reconnected. This makes it possible to use the database normally.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.