Michael Wolfstone
asked on
Transfer Logins from Old SQL server to New SQL server
I thought there was an easy way to transfer logins to the new server by exporting and loading, but I cannot find the SP that I think I used last time (sp_help_revlogin).
Can anyone suggest a simple method to do this.
I tried BCP out for syslogins but can't get the syntax correct.
Can anyone suggest a simple method to do this.
I tried BCP out for syslogins but can't get the syntax correct.
Note that this version has been slightly enhanced to accept the % wildcard character in the @login_name parameter, so if you have three logins: 'yyz1000a' , 'yyz1000b' , 'yyz1000c'
then this will generate a script for all three:
exec master..sp_help_revlogin 'yyz1000%'
But to generate a script for all logins, don't pass anything in the param:
exec master..sp_help_revlogin
then this will generate a script for all three:
exec master..sp_help_revlogin 'yyz1000%'
But to generate a script for all logins, don't pass anything in the param:
exec master..sp_help_revlogin
ASKER
The script parses with no errors; the sp is created with no errors
When I exec it with no parameters I get the following (every time)
/* sp_help_revlogin script
** Generated Mar 14 2014 9:46AM on VSQL */
DECLARE @pwd sysname
IF NOT EXISTS(SELECT sid FROM master..syslogins WHERE name='retailmas')
BEGIN -- only if login does not already exist
PRINT '-- adding login: retailmas'
SET @pwd = CONVERT (varbinary(256), 0x01004DFDDA1BBC36256EBF30 E9D89DF4D1 F42E46CB1D F2DC8D77)
EXEC master..sp_addlogin 'retailmas', @pwd, @sid = 0x98A0037D2529F245B0A51118 8D841E2A, @encryptopt = 'skip_encryption'
ALTER LOGIN [retailmas] WITH CHECK_POLICY = OFF;
END
ELSE PRINT '-- retailmas already exists!'
GO
retailmas is a valid user name but I only get the above.
Your thoughts?
When I exec it with no parameters I get the following (every time)
/* sp_help_revlogin script
** Generated Mar 14 2014 9:46AM on VSQL */
DECLARE @pwd sysname
IF NOT EXISTS(SELECT sid FROM master..syslogins WHERE name='retailmas')
BEGIN -- only if login does not already exist
PRINT '-- adding login: retailmas'
SET @pwd = CONVERT (varbinary(256), 0x01004DFDDA1BBC36256EBF30
EXEC master..sp_addlogin 'retailmas', @pwd, @sid = 0x98A0037D2529F245B0A51118
ALTER LOGIN [retailmas] WITH CHECK_POLICY = OFF;
END
ELSE PRINT '-- retailmas already exists!'
GO
retailmas is a valid user name but I only get the above.
Your thoughts?
What is the result of this query?
SELECT count(*) -- sid, name, status, password
FROM master..syslogins
WHERE name <> 'sa' and name not like '##MS_%' and isntname=0
ORDER BY name
SELECT count(*) -- sid, name, status, password
FROM master..syslogins
WHERE name <> 'sa' and name not like '##MS_%' and isntname=0
ORDER BY name
ASKER
I ran the following (to get a clean parse and exec)
use master
go
SELECT count(*) -- sid, name, status, password
FROM master..syslogins
WHERE name <> 'sa' and name not like '##MS_%' and isntname=0
-- ORDER BY name
Result = 1
use master
go
SELECT count(*) -- sid, name, status, password
FROM master..syslogins
WHERE name <> 'sa' and name not like '##MS_%' and isntname=0
-- ORDER BY name
Result = 1
hmmm ... that suggests you have only one login on this instance. Uncomment the following lines one at a time, and compare the results:
select *
FROM master..syslogins
--WHERE name <> 'sa'
-- and name not like '##MS_%'
-- and isntname=0
select *
FROM master..syslogins
--WHERE name <> 'sa'
-- and name not like '##MS_%'
-- and isntname=0
ah-ha, that might be it ... are your logins NT (Windows) logins instead of SQL logins?
If so, then that last param above is the key...
If so, then that last param above is the key...
ASKER
With NO where I get 143
With where not sa I get 142
With where not sa and name not... I get 138
With Isntname =0 I get 1
I am guessing now that I should remove a reference to 'isntname = 0'
With where not sa I get 142
With where not sa and name not... I get 138
With Isntname =0 I get 1
I am guessing now that I should remove a reference to 'isntname = 0'
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
The information about SQL logins seems to be correct. I tried extracting Windows logins, scripting the extracted data and loading into the new SQL. It seems to work so far.
Open in new window