Give IMPERSONATE permissions on user2 to user1 USE AdventureWorks2022 ĬREATE LOGIN login1 WITH PASSWORD = 'J345#$)thb' ĬREATE LOGIN login2 WITH PASSWORD = 'Uor80$23b' The REVERT statement is executed multiple times moving up the stack until the execution context is set to the original caller. The REVERT statement is then used to reset the execution context to the previous caller. The following example creates a context execution stack by using multiple principals. Using EXECUTE AS and REVERT to switch context After the execution context is reverted, the application can switch context to another principal. Because the value passed to is known only to the caller of the EXECUTE AS statement (in this case, the application), the caller can guarantee that the execution context they establish cannot be changed by the end user that invokes the application. Connection pooling is the maintenance of a group of database connections for reuse by applications across multiple end users. This mechanism is useful in an environment in which connection pooling is used. The execution context set by that statement can only be reverted to the previous context if the calling REVERT WITH COOKIE = varbinary_variable statement contains the correct value. When this statement is run, the Database Engine passes the cookie to varbinary_variable. The EXECUTE AS statement that is used to set the execution context of a session can include the optional clause WITH NO REVERT COOKIE = varbinary_variable. In this case, the execution context remains in effect until the session is dropped. REVERT has no effect if the corresponding EXECUTE AS statement contains the WITH NO REVERT clause. When specified as a standalone statement, REVERT applies to EXECUTE AS statements defined within a batch or session. That is, the execution context for the session remains set to login1. The REVERT statement that is defined inside usp_myproc switches the execution context set inside the module, but does not affect the execution context set outside the module. Sets the execution context of the session to 'login1'. CREATE PROCEDURE dbo.usp_myprocĪssume that in the session in which the stored procedure is run, the execution context of the session is explicitly changed to login1, as shown in the following example. For example, the following stored procedure issues an EXECUTE AS statement followed by a REVERT statement. When specified inside a module, REVERT is applicable only to EXECUTE AS statements defined in the module. REVERT can be specified within a module such as a stored procedure or user-defined function, or as a stand-alone statement. Specifies the cookie that was created in a corresponding EXECUTE AS stand-alone statement. To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |