--Step 1. :: backup the target database
--Step 2. :: Kill connections from the source database
use mastergo
DECLARE @kill varchar(8000) = '';SELECT @kill = @kill + 'kill ' + CONVERT(varchar(5), spid) + ';'FROM master..sysprocesses WHERE dbid = db_id('Reference Data Warehouse')
--Step 3. :: Single User Mode
EXEC(@kill);
ALTER Database [Reference Data Warehouse] SET Single_UserGO--Step 4. :: Disconnect the session!
--Step 5. :: Multi-User Mode
ALTER Database [Reference Data Warehouse] SET Multi_User--##############################################################
GO
EXEC sp_change_users_login 'UPDATE_ONE','MDMDQuser','MDMDQuser'
--First, make sure that this is the problem. This will lists the orphaned users:
EXEC sp_change_users_login 'Report'--If you already have a login id and password for this user, fix it by doing:
EXEC sp_change_users_login 'Auto_Fix', 'user'--If you want to create a new login id and password for this user, fix it by doing:
EXEC sp_change_users_login 'Auto_Fix', 'user', 'login', 'password'