Orphaned users in SQL Server

Source: Internet
Author: User

This issue occurs on the migration value of the database. After moving the value, the database login name and database user name are orphaned, the original data, with the established user name password login can access the database, but the value will not be accessed after the move. And if you try to grant database access to the login, the following error message occurs because the user already exists: ' The login already has an account under another user's name '.

The cause of the error is:
After you transfer the login account and password to the destination server, your users may not have access to the database. The login account is associated with the user by a security identifier (SID), and when you move the database, SQL Server may deny the user access to the database if the SID is inconsistent. This issue is known as orphaned users. Orphaned users can be generated if you use the SQL Server for DTS transport logon feature to transfer logins and passwords. Additionally, an integrated login account that is allowed access to a target server that is in a different domain from the source server can also cause orphaned users to appear.


Here are the workarounds:
1. Find orphaned users. Open Query Analyzer on the destination server, and then run the following code in the user database that you moved: Exec sp_change_users_login ' report ', find to execute after

Use lk96160
Go
Sp_change_users_login ' Update_One ', ' lk96160 ', ' lk96160 '

The general problem will be solved.
2. If a user is an orphaned user, the database user can successfully log on to the server but does not have access to the database. If you try to grant database access to the logon account, the following error message occurs because the user already exists:

Microsoft SQL-DMO (ODBC sqlstate:42000) Error 15023:user or role '%s ' already exists The current database.

or the login name should be changed to dbo for the user, then execute the following code under SA:

exec sp_changedbowner ' sa '

And then do it again:

Use lk96160
Go
Sp_change_users_login ' Update_One ', ' lk96160 ', ' lk96160 '

The general problem will be solved.

Orphaned users in SQL Server

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.