SQL Server client logins are associated with database users

Source: Internet
Author: User

After a database migration, the new SQL Server Client tool sets the association, often with an error:

User, group, or role ' XXX ' already exists in the current database.

Workaround:

First introduce the difference between "login" and "User" in SQL Server, "login" is used for user authentication, and the database "user" account is used for database access and permission validation. The login is associated with the user through a security identifier (SID).

When you restore a database to a different server, the database contains a set of users and permissions, but at this point the database server does not have a login associated with this set of users. This situation is known as "orphaned users". Logon issues cannot be resolved either by creating a new login or by granting the user permission to the corresponding database for a login with the same name because SQL Server reported "error 15023: User or role already exists in the current database."

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

Use database name

Go
Sp_change_users_login ' Update_One ', ' Database user name ', ' Login name '

SQL Server client logins are associated with database users

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.