Domanda

In Sql Server 2000/2005, ho alcuni gruppi di utenti NT a cui è necessario concedere l'accesso a centinaia di procedure memorizzate.

C'è un modo semplice e carino per farlo?

È stato utile?

Soluzione

Ecco uno script che utilizzo per concedere autorizzazioni a molte procedure:

DECLARE @DB  sysname ; set @DB = DB_NAME()
DECLARE @U  sysname ; set @U = QUOTENAME('UserID')

DECLARE @ID           integer,
        @LAST_ID     integer,
        @NAME        varchar(1000),
        @SQL         varchar(4000)

SET @LAST_ID = 0

WHILE @LAST_ID IS NOT NULL
BEGIN
    SELECT @ID = MIN(id)
    FROM dbo.sysobjects
    WHERE id > @LAST_ID  AND type = 'P' AND category = 0

    SET @LAST_ID = @ID

    -- We have a record so go get the name
    IF @ID IS NOT NULL
    BEGIN
        SELECT @NAME = name
        FROM dbo.sysobjects
        WHERE id = @ID

        -- Build the DCL to do the GRANT
        SET @SQL = 'GRANT EXECUTE ON ' + @NAME + ' TO ' + @U

        -- Run the SQL Statement you just generated
        EXEC master.dbo.xp_execresultset @SQL, @DB

    END   
END

È possibile modificare la selezione per accedere a un gruppo più specifico di procedure memorizzate.

Altri suggerimenti

  • Crea un ruolo nel server SQL.
  • Scrivi una sceneggiatura che garantisce il permesso di utilizzare quegli SPROCS.
  • Aggiungi quei gruppi di utenti NT a quel ruolo.
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top