sp_unsetapprole (Transact-SQL)sp_unsetapprole (Transact-SQL)

适用对象:是SQL Server 否Azure SQL 数据库 否Azure Synapse Analytics (SQL DW) 否并行数据仓库 APPLIES TO: yesSQL Server noAzure SQL Database noAzure Synapse Analytics (SQL DW) noParallel Data Warehouse

停用应用程序角色并恢复到前一个安全上下文。Deactivates an application role and reverts to the previous security context.

主题链接图标 Transact-SQL 语法约定Topic link icon Transact-SQL Syntax Conventions

语法Syntax

  
sp_unsetapprole @cookie   

参数Arguments

@票证@cookie
指定在激活应用程序角色时创建的 Cookie。Specifies the cookie that was created when the application role was activated. Cookie 是sp_setapprole (transact-sql)创建的。The cookie is created by sp_setapprole (Transact-SQL). varbinary (8000)varbinary(8000).

备注

**sp_setapprole** 的 cookie **OUTPUT** 参数现记载为 **varbinary(8000)** ,这是正确的最大长度。The cookie OUTPUT parameter for sp_setapprole is currently documented as varbinary(8000) which is the correct maximum length. 但是,目前执行返回 varbinary(50)However the current implementation returns varbinary(50). 应用程序应继续保留varbinary (8000) ,这样,如果 cookie 在将来的版本中返回大小增加,应用程序将继续正常运行。Applications should continue to reserve varbinary(8000) so that the application continues to operate correctly if the cookie return size increases in a future release.

返回代码值Return Code Values

0(成功)和1(失败)0 (success) and 1 (failure)

备注Remarks

使用sp_setapprole激活应用程序角色后,该角色将保持活动状态,直到用户从服务器断开连接或执行sp_unsetapproleAfter an application role is activated by using sp_setapprole, the role remains active until the user either disconnects from the server or executes sp_unsetapprole.

有关应用程序角色的概述,请参阅应用程序角色For an overview of application roles, see Application Roles.

权限Permissions

要求公共的成员身份以及在激活应用程序角色时保存的 cookie 的知识。Requires membership in public and knowledge of the cookie saved when the application role was activated.

示例Examples

以下示例使用密码 Sales11 激活 fdsd896#gfdbfdkjgh700mM 应用程序角色并创建一个 cookie。The following example activates the Sales11 application role with password fdsd896#gfdbfdkjgh700mM, and creates a cookie. 该示例返回当前用户的名称,然后通过执行sp_unsetapprole恢复为原始上下文。The example returns the name of the current user, and then reverts to the original context by executing 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   

另请参阅See Also

sp_setapprole (Transact-SQL) sp_setapprole (Transact-SQL)
系统存储过程 (Transact-SQL) System Stored Procedures (Transact-SQL)
安全存储过程 (Transact-sql) Security Stored Procedures (Transact-SQL)
CREATE APPLICATION ROLE (Transact-SQL) CREATE APPLICATION ROLE (Transact-SQL)
DROP APPLICATION ROLE (Transact-SQL)DROP APPLICATION ROLE (Transact-SQL)