|
1 | 1 | ---
|
2 | 2 | title: Internal Activation Context
|
3 |
| -description: "This topic describes the execution context for a stored procedure that is started by internal activation." |
| 3 | +description: Learn about the execution context for a stored procedure that is started by internal activation. |
4 | 4 | author: rwestMSFT
|
5 | 5 | ms.author: randolphwest
|
6 | 6 | ms.reviewer: mikeray, maghan
|
7 |
| -ms.date: "03/30/2022" |
| 7 | +ms.date: 07/17/2025 |
8 | 8 | ms.service: sql
|
9 | 9 | ms.subservice: configuration
|
10 | 10 | ms.topic: conceptual
|
11 | 11 | ---
|
12 | 12 |
|
13 |
| -# Internal Activation Context |
| 13 | +# Internal activation context |
14 | 14 |
|
15 | 15 | [!INCLUDE [sql-asdbmi](../../includes/applies-to-version/sql-asdbmi.md)]
|
16 | 16 |
|
17 |
| -This topic describes the execution context for a stored procedure that is started by internal activation. |
| 17 | +This article describes the execution context for a stored procedure that is started by internal activation. |
18 | 18 |
|
19 |
| -## Security Context |
| 19 | +## Security context |
20 | 20 |
|
21 | 21 | A queue configured for activation must also specify the user that the activation stored procedure runs as. SQL Server impersonates this user before starting the stored procedure.
|
22 | 22 |
|
23 | 23 | When the stored procedure also specifies an EXECUTE AS clause, two impersonations occur. SQL Server first impersonates the user specified for the queue and executes the stored procedure. When the stored procedure executes, the procedure impersonates the user specified in the EXECUTE AS clause of the procedure.
|
24 | 24 |
|
25 |
| -Notice that the user specified for a remote service binding is generally a different user from the user specified for activation. The permissions required for each user also differ. The remote service binding user does not need permission to read from the queue or execute stored procedures in the database, while the user specified for activation does not need permission to send messages to the service. For more information on user permissions, see [Identity and Access Control (Service Broker)](identity-and-access-control.md) and [Service Broker Dialog Security](service-broker-dialog-security.md). |
| 25 | +The user specified for a remote service binding is generally a different user from the user specified for activation. The permissions required for each user also differ. The remote service binding user doesn't need permission to read from the queue or execute stored procedures in the database, while the user specified for activation doesn't need permission to send messages to the service. For more information on user permissions, see [Identity and Access Control (Service Broker)](identity-and-access-control.md) and [Service Broker Dialog Security](service-broker-dialog-security.md). |
26 | 26 |
|
27 |
| -## Session Settings |
| 27 | +## Session settings |
28 | 28 |
|
29 | 29 | Service Broker executes internally activated service programs on a background session distinct from the connection that created the message. The options set for this session are the default options for the database.
|
30 | 30 |
|
31 |
| -Within a session started by Service Broker, SQL Server writes the output of PRINT and RAISERROR statements to the SQL Server error log. Service Broker does not provide parameters to an activated stored procedure. Service Broker does not consider return values from an activated stored procedure and does not process result sets from an activated stored procedure. |
| 31 | +Within a session started by Service Broker, SQL Server writes the output of PRINT and RAISERROR statements to the SQL Server error log. Service Broker doesn't provide parameters to an activated stored procedure. Service Broker doesn't consider return values from an activated stored procedure and doesn't process result sets from an activated stored procedure. |
32 | 32 |
|
33 |
| -## Transaction Context |
| 33 | +## Transaction context |
34 | 34 |
|
35 |
| -An activated stored procedure is responsible for managing transactions. SQL Server does not start a transaction before activating the stored procedure, and the stored procedure runs in a different transaction context than the internal operation that activates the procedure. For a discussion of managing transactions in activated stored procedures, see [Transactional Messaging](transactional-messaging.md). |
| 35 | +An activated stored procedure is responsible for managing transactions. SQL Server doesn't start a transaction before activating the stored procedure, and the stored procedure runs in a different transaction context than the internal operation that activates the procedure. For a discussion of managing transactions in activated stored procedures, see [Transactional Messaging](transactional-messaging.md). |
36 | 36 |
|
37 |
| -## Failure Detection |
| 37 | +## Failure detection |
38 | 38 |
|
39 |
| -An activated stored procedure must receive messages from the queue that activated the procedure. If the stored procedure exits without receiving messages or the queue monitor detects that the stored procedure is not receiving messages after a short time-out, the queue monitor considers the stored procedure to have failed. In this case, the queue monitor stops activating the stored procedure. |
| 39 | +An activated stored procedure must receive messages from the queue that activated the procedure. If the stored procedure exits without receiving messages, or the queue monitor detects that the stored procedure isn't receiving messages after a short timeout, the queue monitor considers the stored procedure to have failed. In this case, the queue monitor stops activating the stored procedure. |
40 | 40 |
|
41 |
| -## See also |
| 41 | +## Monitor |
| 42 | + |
| 43 | +To check the user running the activation procedure, you can either use Extended Events (the `broker_activation` event, with `username` and `server_principal_name` actions), or the [sys.dm_broker_activated_tasks](../../relational-databases/system-dynamic-management-views/sys-dm-broker-activated-tasks-transact-sql.md) dynamic management view, which returns the database `principal_id` configured in the queue. |
| 44 | + |
| 45 | +## Related content |
42 | 46 |
|
43 | 47 | - [PRINT (Transact-SQL)](../../t-sql/language-elements/print-transact-sql.md)
|
44 | 48 | - [RAISERROR (Transact-SQL)](../../t-sql/language-elements/raiserror-transact-sql.md)
|
45 |
| -- [Implementing Internal Activation](implementing-internal-activation.md) |
| 49 | +- [Implement internal activation in Service Broker](implementing-internal-activation.md) |
0 commit comments