Ano-Tech Computers
Enter keyword:

SQL Server 2005: Map login-user to an existing (orphaned) database-user
Problem:
When migrating a database from one SQL Server to another, the database itself will contain database-users with no corresponding login-user. Attempting to "map" a new login-user to one of those existing (orphaned) database-users will FAIL because "the database-user already exists" (sic)
 
Solution:
See http://www.mssqltips.com/tip.asp?tip=1590 for detailed information. The short version:

USE DatabaseName
GO

sp_change_users_login @Action='update_one',
@UserNamePattern='DatabaseUser1',
@LoginName='LoginUser1'
GO

Using attach/detach for migration is pretty useless without this, so why did they not implement this in the management GUI??
 
Discuss this solution
Did this article solve your problem? Yes No Did not apply

We welcome anyone who is willing to contribute to this public knowledge base, contact siteadmin@atc.no if you have information you would like to share. The idea is not to replace the commercial support sites, but to publish those hard-to-find solutions you've found yourself looking for over and over again.

Show all articles