Creating Logins for Databases Restored to a Replacement SQL Server

Create.logins.sql

— Create source-server logins on target-server

USE Master
Go

DECLARE logincur CURSOR
FAST_FORWARD
FOR
SELECT [name], encryptedpassword, defaultdb,
deflanguage, sid, encryptopt
FROM Northwind..logins

DECLARE @loginame varchar(30),
@passwd nvarchar(128),
@defdb nvarchar(128),
@deflang nvarchar(128),
@sid varbinary(85),
@encryptopt varchar(30)

OPEN logincur

FETCH NEXT FROM logincur 
INTO @loginame, @passwd, @defdb, 
@deflang, @sid, @encryptopt

WHILE (@@fetch_status = 0)
BEGIN

EXEC master..sp_addlogin
@loginame, @passwd, @defdb,
@deflang, @sid, @encryptopt

FETCH NEXT FROM logincur 
INTO @loginame, @passwd, @defdb, 
@deflang, @sid, @encryptopt

END

CLOSE logincur
DEALLOCATE logincur
GO

Published with the express written permission of the author. Copyright 2001.

Pages: 1 2




Array

No comments yet... Be the first to leave a reply!