sp_unsetapprole (Transact-SQL)

停用应用程序角色并恢复到前一个安全上下文。

主题链接图标 Transact-SQL 语法约定

语法

sp_unsetapprole @cookie 

参数

  • @cookie
    指定在激活应用程序角色时创建的 Cookie。 该 Cookie 是由sp_setapprole (Transact-SQL)创建的。 varbinary(8000).

    注意注意

    sp_setapprole 的 cookie OUTPUT 参数当前记载为 varbinary(8000),这是正确的最大长度。 但是,当前实现返回 varbinary(50)。 应用程序应继续保留 varbinary(8000),以便当 cookie 在将来的版本中返回大小增量时,应用程序可继续正确运行。

返回代码值

0(成功)或 1(失败)

注释

通过使用 sp_setapprole 来激活应用程序角色之后,该角色将保持活动状态,直到该用户与服务器断开连接,或执行 sp_unsetapprole

有关应用程序角色的概述,请参阅应用程序角色

权限

需要 public 中的成员身份以及在激活应用程序角色时保存的 Cookie 知识。

示例

以下示例使用密码 fdsd896#gfdbfdkjgh700mM 激活 Sales11 应用程序角色并创建一个 cookie。 该示例返回当前用户的名称,然后通过执行 sp_unsetapprole 恢复到原始上下文中。

DECLARE @cookie varbinary(8000);
EXEC sp_setapprole 'Sales11', 'fdsd896#gfdbfdkjgh700mM'
    , @fCreateCookie = true, @cookie = @cookie OUTPUT;
-- The application role is now active.
SELECT USER_NAME();
-- This will return the name of the application role, Sales11.
EXEC sp_unsetapprole @cookie;
-- The application role is no longer active.
-- The original context has now been restored.
GO
SELECT USER_NAME();
-- This will return the name of the original user. 
GO 

请参阅

参考

sp_setapprole (Transact-SQL)

系统存储过程 (Transact-SQL)

安全存储过程 (Transact-SQL)

CREATE APPLICATION ROLE (Transact-SQL)

DROP APPLICATION ROLE (Transact-SQL)