begin process at 2008 07 04 09:41:22
1 204 528 membres
70 nouveaux aujourd'hui
14 116 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

SQL SERVER 2000 - EXPORTER LES COMPTES UTILISATEURS SQL ET NT EXISTANT SUR LE SERVEUR


Information sur la source

Catégorie :Migration Classé sous : migration, compte, sql Niveau : Expert Date de création : 16/01/2007 Vu : 2 794

Note :
9 / 10 - par 1 personne
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note


Description

Dans le cadre de migration de bases de données SQL Server, il faut absolument transférer les comptes provenant de la machine SQL Server 2000.
Un script fourni par Microsoft permet d'effectuer ce travail automatiquement, on peut alors recréer les comptes SQL sur la nouvelle machine avant de restaurer les bases.

Vous trouverez ce script sur le site du support Microsoft :
- http://support.microsoft.com/kb/246133

Source

  • ----- Begin Script, Create sp_help_revlogin procedure -----
  • USE master
  • GO
  • IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
  • DROP PROCEDURE sp_hexadecimal
  • GO
  • CREATE PROCEDURE sp_hexadecimal
  • @binvalue varbinary(256),
  • @hexvalue varchar(256) OUTPUT
  • AS
  • 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') IS NOT NULL
  • DROP PROCEDURE sp_help_revlogin
  • GO
  • CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
  • DECLARE @name sysname
  • DECLARE @xstatus int
  • DECLARE @binpwd varbinary (256)
  • DECLARE @txtpwd sysname
  • DECLARE @tmpstr varchar (256)
  • DECLARE @SID_varbinary varbinary(85)
  • DECLARE @SID_string varchar(256)
  • IF (@login_name IS NULL)
  • DECLARE login_curs CURSOR FOR
  • SELECT sid, name, xstatus, password FROM master..sysxlogins
  • WHERE srvid IS NULL AND name <> 'sa'
  • ELSE
  • DECLARE login_curs CURSOR FOR
  • SELECT sid, name, xstatus, password FROM master..sysxlogins
  • WHERE srvid IS NULL AND name = @login_name
  • OPEN login_curs
  • FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd
  • 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 'DECLARE @pwd sysname'
  • WHILE (@@fetch_status <> -1)
  • BEGIN
  • IF (@@fetch_status <> -2)
  • BEGIN
  • PRINT ''
  • SET @tmpstr = '-- Login: ' + @name
  • PRINT @tmpstr
  • IF (@xstatus & 4) = 4
  • BEGIN -- NT authenticated account/group
  • IF (@xstatus & 1) = 1
  • BEGIN -- NT login is denied access
  • SET @tmpstr = 'EXEC master..sp_denylogin ''' + @name + ''''
  • PRINT @tmpstr
  • END
  • ELSE BEGIN -- NT login has access
  • SET @tmpstr = 'EXEC master..sp_grantlogin ''' + @name + ''''
  • PRINT @tmpstr
  • END
  • END
  • ELSE BEGIN -- SQL Server authentication
  • IF (@binpwd IS NOT NULL)
  • BEGIN -- Non-null password
  • EXEC sp_hexadecimal @binpwd, @txtpwd OUT
  • IF (@xstatus & 2048) = 2048
  • SET @tmpstr = 'SET @pwd = CONVERT (varchar(256), ' + @txtpwd + ')'
  • ELSE
  • SET @tmpstr = 'SET @pwd = CONVERT (varbinary(256), ' + @txtpwd + ')'
  • PRINT @tmpstr
  • EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
  • SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name
  • + ''', @pwd, @sid = ' + @SID_string + ', @encryptopt = '
  • END
  • ELSE BEGIN
  • -- Null password
  • EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
  • SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name
  • + ''', NULL, @sid = ' + @SID_string + ', @encryptopt = '
  • END
  • IF (@xstatus & 2048) = 2048
  • -- login upgraded from 6.5
  • SET @tmpstr = @tmpstr + '''skip_encryption_old'''
  • ELSE
  • SET @tmpstr = @tmpstr + '''skip_encryption'''
  • PRINT @tmpstr
  • END
  • END
  • FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd
  • END
  • CLOSE login_curs
  • DEALLOCATE login_curs
  • RETURN 0
  • GO
  • ----- End Script -----
----- Begin Script, Create sp_help_revlogin procedure -----

USE master
GO
IF OBJECT_ID ('sp_hexadecimal') IS NOT NULL
  DROP PROCEDURE sp_hexadecimal
GO
CREATE PROCEDURE sp_hexadecimal
    @binvalue varbinary(256),
    @hexvalue varchar(256) OUTPUT
AS
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') IS NOT NULL
  DROP PROCEDURE sp_help_revlogin 
GO
CREATE PROCEDURE sp_help_revlogin @login_name sysname = NULL AS
DECLARE @name    sysname
DECLARE @xstatus int
DECLARE @binpwd  varbinary (256)
DECLARE @txtpwd  sysname
DECLARE @tmpstr  varchar (256)
DECLARE @SID_varbinary varbinary(85)
DECLARE @SID_string varchar(256)

IF (@login_name IS NULL)
  DECLARE login_curs CURSOR FOR 
    SELECT sid, name, xstatus, password FROM master..sysxlogins 
    WHERE srvid IS NULL AND name <> 'sa'
ELSE
  DECLARE login_curs CURSOR FOR 
    SELECT sid, name, xstatus, password FROM master..sysxlogins 
    WHERE srvid IS NULL AND name = @login_name
OPEN login_curs 
FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd
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 'DECLARE @pwd sysname'
WHILE (@@fetch_status <> -1)
BEGIN
  IF (@@fetch_status <> -2)
  BEGIN
    PRINT ''
    SET @tmpstr = '-- Login: ' + @name
    PRINT @tmpstr 
    IF (@xstatus & 4) = 4
    BEGIN -- NT authenticated account/group
      IF (@xstatus & 1) = 1
      BEGIN -- NT login is denied access
        SET @tmpstr = 'EXEC master..sp_denylogin ''' + @name + ''''
        PRINT @tmpstr 
      END
      ELSE BEGIN -- NT login has access
        SET @tmpstr = 'EXEC master..sp_grantlogin ''' + @name + ''''
        PRINT @tmpstr 
      END
    END
    ELSE BEGIN -- SQL Server authentication
      IF (@binpwd IS NOT NULL)
      BEGIN -- Non-null password
        EXEC sp_hexadecimal @binpwd, @txtpwd OUT
        IF (@xstatus & 2048) = 2048
          SET @tmpstr = 'SET @pwd = CONVERT (varchar(256), ' + @txtpwd + ')'
        ELSE
          SET @tmpstr = 'SET @pwd = CONVERT (varbinary(256), ' + @txtpwd + ')'
        PRINT @tmpstr
	EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
        SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name 
          + ''', @pwd, @sid = ' + @SID_string + ', @encryptopt = '
      END
      ELSE BEGIN 
        -- Null password
	EXEC sp_hexadecimal @SID_varbinary,@SID_string OUT
        SET @tmpstr = 'EXEC master..sp_addlogin ''' + @name 
          + ''', NULL, @sid = ' + @SID_string + ', @encryptopt = '
      END
      IF (@xstatus & 2048) = 2048
        -- login upgraded from 6.5
        SET @tmpstr = @tmpstr + '''skip_encryption_old''' 
      ELSE 
        SET @tmpstr = @tmpstr + '''skip_encryption'''
      PRINT @tmpstr 
    END
  END
  FETCH NEXT FROM login_curs INTO @SID_varbinary, @name, @xstatus, @binpwd
  END
CLOSE login_curs 
DEALLOCATE login_curs 
RETURN 0
GO
 ----- End Script -----

Conclusion

Bon coding

Romelard Fabrice [MVP]
    Aucun commentaire pour le moment.

Ajouter un commentaire

Pub



Appels d'offres

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Boutique

Boutique de goodies CodeS-SourceS