SQL Server User / Logins Mismatch PDF Print

When restoring a SQL database from one machine to another you may find that the Users for the database are not associated with any Login - even if the login exists. Sometimes it is possible to create the Login (if necessary) and the delete the User and recreate it, but this is not always possible or desireable. In this case, the following procedure may be of use to you.

 

USE <database>
go
EXEC sp_change_users_login 'Auto_Fix', '<name>', NULL, '<password>'
go 

This should associate the User specified by <name> with a login of the same name. If the login does not already exist, it should be created with the given password.