begin process at 2012 05 25 11:50:32
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Migration

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

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


 Information sur la source

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

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Migration Classé sous :migration, compte, sql Niveau :Expert Date de création :16/01/2007 Vu :8 238

Auteur : fabrice69

Ecrire un message privé
Site perso
Ce membre participe au partage de revenus publicitaires
Commentaire sur cette source (1)
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]


 Sources du même auteur

SQL SERVER - OBTENIR LES VALEURS CORRESPONDANT A DES UNICODE
SQL SERVER 2000 - VIDER ET COMPACTER TOUTES LES BASES DE DON...
SQL SERVER 2005 : OBTENIR LA LISTE DES BASES DE CONTENU D'UN...
SQL SERVER - OBTENIR LA POSITION DU PREMIER CHIFFRE D'UNE CH...
SQL SERVER - UPDATE D'UNE TABLE EN BOUCLE PAR LOT

 Sources de la même categorie

Source avec Zip DUMP LOAD D'UNE BASE DE DONNÉES par pneau
SQL SERVER 2000 - COMPACTER TOUTES LES BASES DE DONNÉES DU S... par fabrice69
SQL SERVER - RESTAURER UNE BASE ET REJOUER LE LOG DE TRANSAC... par fabrice69
SQL SERVER - RESTAURER UNE BASE DEPUIS UN BACKUP par fabrice69

 Sources en rapport avec celle ci

Source avec une capture T-SQL - SPLIT SANS TABLE TEMPORAIRE par TheOnlyMaX
TROUVER LES PROCHAINS ANNIVERSAIRES par zefo
REQUÊTE SQL POUR DÉTERMINER L'ESPACE OCCUPÉ DANS LES TABLESP... par sgoriaud
Source avec Zip DUMP LOAD D'UNE BASE DE DONNÉES par pneau
Source avec Zip LISTE DES PAYS DU MONDE EN FRANÇAIS/ANGLAIS DANS UNE BASE SQ... par Joe_le_mort

Commentaires et avis

Commentaire de fabrice69 le 08/06/2010 11:08:37 administrateur CS

Pour ceux qui souhaitent le m'eme script pour SQL Server 2005 :
- http://support.microsoft.com/kb/918992

Fabrice Romelard [MVP]

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Migration SQL Server vers Oracle : ordre de tri [ par Thanos_the_yopper ] Bonjour,Nous venons de migrer une base de données de SQL Server vers Oracle et on a des problèmes au niveau des tris (Order By asc). Sous SQL Server, Petit problème avec migration SQL Server 2000 à 2005 [ par white_mage ] Bonjour,J'ai un petit souci de migration et j'espère que quelqu'un pourra m'aider.Nous avons une ancienne application Access ADP qui tire ses données identifiants de connexion du compte sys.dba [ par herve_labenere ] Je tente actuellement de réaliser en C# un lecteur MP3 couplé au moteur de  bdd Sql Server 2005 Express. Ma Bdd stockera le chemin de tous les fichier migration de base de donnée SQL Server vers Oarcle 9i [ par issam164 ] Bonjour, Je recherche tout retour d'expérience, méthodes ,outils pour migration de serveur SQL Server vers Oracle V9iMe probleme migration des users sql server 6.5 vers 2000 [ par yeye75 ] Bonjour,Je travaille actuellement à la migration de sql server 6.5 à sql server 2000 via l'assistant de migration. Les objets tables\PS ont été correc SQL Dans un domaine [ par cretthie ] Bonjour,J'ai acheter un sql standard edition, j'ai monté mon iis avec mon nom de domaine sur dyndns ou autre, je sais plus.Tout d'abord, il me semble sql server 2005 et migration de donnees [ par ghano81 ] bonjour jé un ptit probleme concernant les base de données j'ai crer une base de donnee en access et  maintenant  je veux la exploiter  en sql server migration oracle vers sql server [ par verbeyst ] Bonjour,J'implémente une application web qui se connecte sur une db oracle. Je voudrais mainetant  "générer une copie" de ma db oracle en sql server.V Migration de sql vers oracle [ par laymouna98 ] Salut à tous SVP je veux une version complète d'un outil gratuit qui me permet de migrer ma base SQL Server 2000 vers Oracle 10g j'ai essayé avec Migration sql serveur 2005 vers 2000 [ par nuth ] Bonjour, Je souhaiterai migrer une base de données sql serveur 2005 vers 2000. Après quelques recherches sur google je n'ai rien trouvé donc je me de


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,858 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales