Monday, October 30, 2017

db Backup and Restore....to make life easier

--############################################################

--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')

EXEC(@kill);
--Step 3. :: Single User Mode
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'





No comments:

Post a Comment