How to transfer the server logins from SQL Server 2000 to SQL Server 2012 -


i have migrate database sql server 2000 sql server 2012. how transfer server logins sql server 2000 sql server 2012? server logins below server security.

run following script on 2000 sql server:

use master  go  if object_id ('sp_hexadecimal') not null  drop procedure sp_hexadecimal  go  create procedure sp_hexadecimal  @binvalue varbinary(256),  @hexvalue varchar(256) output   declare @charvalue varchar(256)  declare @i int  declare @length int  declare @hexstring char(16)  select @charvalue = '0x'  select @i = 1  select @length = datalength (@binvalue)  select @hexstring = '0123456789abcdef'  while (@i <= @length)  begin  declare @tempint int  declare @firstint int  declare @secondint int  select @tempint = convert(int, substring(@binvalue,@i,1))  select @firstint = floor(@tempint/16)  select @secondint = @tempint - (@firstint*16)  select @charvalue = @charvalue +  substring(@hexstring, @firstint+1, 1) +  substring(@hexstring, @secondint+1, 1)  select @i = @i + 1  end  select @hexvalue = @charvalue  go   if object_id ('sp_help_revlogin_2000_to_2005') not null  drop procedure sp_help_revlogin_2000_to_2005  go  create procedure sp_help_revlogin_2000_to_2005   @login_name sysname = null,  @include_db bit = 0,  @include_role bit = 0    declare @name sysname  declare @xstatus int  declare @binpwd varbinary (256)  declare @dfltdb varchar (256)  declare @txtpwd sysname  declare @tmpstr varchar (256)  declare @sid_varbinary varbinary(85)  declare @sid_string varchar(256)   if (@login_name null)  declare login_curs cursor static  select sid, [name], xstatus, password, isnull(db_name(dbid), 'master')  master.dbo.sysxlogins  srvid null ,  [name] <> 'sa'  else  declare login_curs cursor  select sid, [name], xstatus, password, isnull(db_name(dbid), 'master')  master.dbo.sysxlogins  srvid null ,  [name] = @login_name   open login_curs   fetch next login_curs @sid_varbinary, @name, @xstatus, @binpwd, @dfltdb   if (@@fetch_status = -1)  begin  print 'no login(s) found.'  close login_curs  deallocate login_curs  return -1  end   set @tmpstr = '/* sp_help_revlogin script '  print @tmpstr  set @tmpstr = '** generated '  + convert (varchar, getdate()) + ' on ' + @@servername + ' */'  print @tmpstr  print ''  print ''  print ''  print '/***** create logins *****/'   while @@fetch_status = 0  begin  print ''  set @tmpstr = '-- login: ' + @name  print @tmpstr   if (@xstatus & 4) = 4  begin -- nt authenticated account/group  if (@xstatus & 1) = 1  begin -- nt login denied access  set @tmpstr = '' --'exec master..sp_denylogin ''' + @name + ''''  print @tmpstr  end  else  begin -- nt login has access  set @tmpstr = 'if not exists (select * sys.server_principals [name] = ''' + @name + ''')'  print @tmpstr  set @tmpstr = char(9) + 'create login [' + @name + '] windows'  print @tmpstr  end  end  else  begin -- sql server authentication  exec sp_hexadecimal @sid_varbinary, @sid_string out   if (@binpwd not null)  begin -- non-null password  exec sp_hexadecimal @binpwd, @txtpwd out  set @tmpstr = 'create login [' + @name + '] password=' + @txtpwd + ' hashed'  end  else  begin -- null password  set @tmpstr = 'create login [' + @name + '] password='''''  end   set @tmpstr = @tmpstr + ', check_policy=off, sid=' + @sid_string  print @tmpstr  end   fetch next login_curs @sid_varbinary, @name, @xstatus, @binpwd, @dfltdb  end   if @include_db = 1  begin  print ''  print ''  print ''  print '/***** set default databases *****/'   fetch first login_curs @sid_varbinary, @name, @xstatus, @binpwd, @dfltdb   while @@fetch_status = 0  begin  print ''  set @tmpstr = '-- login: ' + @name  print @tmpstr   set @tmpstr = 'alter login [' + @name + '] default_database=[' + @dfltdb + ']'  print @tmpstr   fetch next login_curs @sid_varbinary, @name, @xstatus, @binpwd, @dfltdb  end  end   if @include_role = 1  begin  print ''  print ''  print ''  print '/***** set server roles *****/'   fetch first login_curs @sid_varbinary, @name, @xstatus, @binpwd, @dfltdb   while @@fetch_status = 0  begin  print ''  set @tmpstr = '-- login: ' + @name  print @tmpstr   if @xstatus &16 = 16 -- sysadmin  begin  set @tmpstr = 'exec master.dbo.sp_addsrvrolemember @loginame=''' + @name + ''', @rolename=''sysadmin'''  print @tmpstr  end   if @xstatus &32 = 32 -- securityadmin  begin  set @tmpstr = 'exec master.dbo.sp_addsrvrolemember @loginame=''' + @name + ''', @rolename=''securityadmin'''  print @tmpstr  end   if @xstatus &64 = 64 -- serveradmin  begin  set @tmpstr = 'exec master.dbo.sp_addsrvrolemember @loginame=''' + @name + ''', @rolename=''serveradmin'''  print @tmpstr  end   if @xstatus &128 = 128 -- setupadmin  begin  set @tmpstr = 'exec master.dbo.sp_addsrvrolemember @loginame=''' + @name + ''', @rolename=''setupadmin'''  print @tmpstr  end   if @xstatus &256 = 256 --processadmin  begin  set @tmpstr = 'exec master.dbo.sp_addsrvrolemember @loginame=''' + @name + ''', @rolename=''processadmin'''  print @tmpstr  end   if @xstatus &512 = 512 -- diskadmin  begin  set @tmpstr = 'exec master.dbo.sp_addsrvrolemember @loginame=''' + @name + ''', @rolename=''diskadmin'''  print @tmpstr  end   if @xstatus &1024 = 1024 -- dbcreator  begin  set @tmpstr = 'exec master.dbo.sp_addsrvrolemember @loginame=''' + @name + ''', @rolename=''dbcreator'''  print @tmpstr  end   if @xstatus &4096 = 4096 -- bulkadmin  begin  set @tmpstr = 'exec master.dbo.sp_addsrvrolemember @loginame=''' + @name + ''', @rolename=''bulkadmin'''  print @tmpstr  end   fetch next login_curs @sid_varbinary, @name, @xstatus, @binpwd, @dfltdb  end  end   close login_curs  deallocate login_curs  return 0  go  exec sp_help_revlogin_2000_to_2005 @login_name=null, @include_db=1, @include_role=1 go 

the copy/save output , run on 2012 server

for more info see this


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -