Restore Database and Database User

When restoring an SQL Server 2005 database from a different database instance the database login will be orphaned. Use this SQL script to fix the orphaned login.

sp_change_users_login ‘Auto_Fix’, ‘user’, NULL, ‘password’

Actual syntax:

sp_change_users_login [ @Action = ] ‘action’     [ , [ @UserNamePattern = ] ‘user’ ]     [ , [ @LoginName = ] ‘login’ ]         [ , [ @Password = ] ‘password’ ]

See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_ca-cz_8qzy.asp