SQL Server always reports 4052, 15023, and so on when a user logs on due to database migration.

Source: Internet
Author: User

Due to weeks of company database migration led to work in Monday, the database connection is not a problem, tinkering with the old, on-line Niang finally found the problem point.

Describes the difference between "login" and "User" in SQL Server, "logon" for user authentication, and database "user" account 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 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". The logon issue 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", in order to resolve this issue, the system stored procedure SP must be called _change_users_login, the following is the specific usage:

Use Newzs

Go
Sp_change_users_login ' Update_One ', ' infos1 ', ' infos1 '

where Newzs for the existence of orphaned users of the database, Update_One is the parameters of the stored procedure, indicating that only one user is processed, the previous infos1 is "user", the latter infos1 is "login", the above SQL represents the server login "INFOS1" and Newzs database User "INFOS1" reconnect. This will allow the database to be used normally.

SQL Server always reports 4052, 15023, and so on when a user logs on due to database migration.

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.