LinkedIn

Tuesday, 21 August 2012

Attach Sql Database

This is just a little reminder to me on how to attach an existing database:

EXEC sp_attach_db @dbname = 'MazdaCleanSitecore_WebTarget',
@filename1 = 'D:\Data\Mazda\MazdaCleanSitecore_WebTarget.mdf', @filename2 = 'D:\Data\Mazda\MazdaCleanSitecore_WebTarget_1.ldf'
 
Fixing an orphaned user.
This used to be a pain to fix, but currently (SQL Server 2000, SP3) there is a stored procedure that does the heavy lifting.

All of these instructions should be done as a database admin, with the restored database selected.
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'
Thanks
RuSs