home
training courses
why choose us?
solutions
support
company
LearnItFirst User Forum
Welcome Guest
Search
|
New Posts
|
Members
|
Log In
|
Register
SQL Server Forum - LearnItFirst.com
»
SQL Server Scripts, Code Samples and SSMS Custom Reports
»
All SQL Server Versions
»
Copy Logins From One SQL Server to Another and Keep SID the Same
Copy Logins From One SQL Server to Another and Keep SID the Same
Options
Previous Topic
·
Next Topic
Scott Whigham
Posted:
Monday, August 28, 2006 11:19:48 AM
Rank: Super Mod
Joined: 3/20/2006
Posts: 476
Points: 1,053
Where do you live?: Dallas, TX
Code:
/*
Author: Scott Whigham from
http://www.LearnSqlServer.com/
Description: This script generates a text file containing all SQL Server authentication logins except 'sa'.
It then suggests you load the data from this file on a second server. This will synchronize logins between two servers so that all
SQL Server authentication logins have the exact same SIDs.
Note: if you use this script instead of sp_change_users_login, you won't have the orphaned logins everytime you backup/restore your
database on another server/instance.
Misc Notes: This script should only be run by the most confident of DBAs; this is
not for the light-hearted! It adds new logins to the target server and, perhaps
most importantly, stores logins and passwords (encrypted) in a text file.
Versions: SQL Server Only tested on SQL Server 2000 (does not work with SQL Server 2005)
Creation Date: August 28, 2006
For more scripts like this one, visit
http://forums.learnsqlserver.com/codesamples.aspx
*/
-- First, get the original logins from the Source server:
EXEC master.dbo.xp_cmdshell
'bcp "SELECT * FROM master.dbo.sysxlogins WHERE name NOT IN (''sa'',''guest'') AND Name NOT LIKE ''%\%''" queryout c:\logins.txt -T -c -S"Source Server Goes Here"'
-- Log on to the destination server and run this script:
EXEC sp_configure 'allow updates', 1
RECONFIGURE WITH OVERRIDE
GO
EXEC master.dbo.xp_cmdshell 'bcp master.dbo.sysxlogins in c:\logins.txt -T -c -S"Destination Server Goes Here"'
GO
EXEC sp_configure 'allow updates', 0
RECONFIGURE WITH OVERRIDE
GO
-- Cleanup the original text file:
EXEC master.dbo.xp_cmdshell 'del c:\logins.txt'
Back to top
Users browsing this topic
Guest
Forum Jump
SQL Server Database Administration
- General SQL Database Question & Answer
- Backup, Recovery and Disaster Recovery
- SQL Server Security
- Integration Services (SSIS) and DTS
Transact-SQL Programming
- DML (SELECT, INSERT, UPDATE, DELETE) Questions
- Stored Procedures, Triggers, & Functions
SQL Server Scripts, Code Samples and SSMS Custom Reports
- All SQL Server Versions
- SQL Server 2005/2008
- SQL Server Management Studio Custom Reports
Customer Service
- Video Requests
You
cannot
post new topics in this forum.
You
cannot
reply to topics in this forum.
You
cannot
delete your posts in this forum.
You
cannot
edit your posts in this forum.
You
cannot
create polls in this forum.
You
cannot
vote in polls in this forum.
SQL Server 2005 DBA Training Videos
SQL Server 2008 DBA Training Videos
Email this topic
RSS Feed
Watch this topic
Print this topic
Normal
Threaded