You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> The Azure SQL trigger is only supported on **Premium and Dedicated** plans. Consumption is not supported.
17
+
> The Azure SQL trigger is only supported on **Premium and Dedicated** plans. Consumption is not currently supported.
16
18
17
19
The Azure SQL trigger uses [SQL change tracking](/sql/relational-databases/track-changes/about-change-tracking-sql-server) functionality to monitor a SQL table for changes and trigger a function when a row is created, updated, or deleted.
18
20
19
21
For configuration details for change tracking for use with the Azure SQL trigger, see [Set up change tracking](#set-up-change-tracking-required). For information on setup details of the Azure SQL extension for Azure Functions, see the [SQL binding overview](./functions-bindings-azure-sql.md).
20
22
21
-
## Example usage
22
-
<aid="example"></a>
23
+
## Functionality Overview
23
24
24
-
::: zone pivot="programming-language-csharp"
25
+
The Azure SQL Trigger binding uses a polling loop to check for changes, triggering the user function when changes are detected. At a high level the loop looks like this:
26
+
27
+
```
28
+
while (true) {
29
+
1. Get list of changes on table - up to a maximum number controlled by the Sql_Trigger_MaxBatchSize setting
30
+
2. Trigger function with list of changes
31
+
3. Wait for delay controlled by Sql_Trigger_PollingIntervalMs setting
32
+
}
33
+
```
34
+
35
+
Changes will always be processed in the order that their changes were made, with the oldest changes being processed first. A couple notes about this:
36
+
37
+
1. If changes to multiple rows are made at once the exact order that they'll be sent to the function is based on the order returned by the CHANGETABLE function
38
+
2. Changes are "batched" together for a row - if multiple changes are made to a row between each iteration of the loop then only a single change entry will exist for that row that shows the difference between the last processed state and the current state
39
+
3. If changes are made to a set of rows, and then another set of changes are made to half of those same rows then the half that wasn't changed a second time will be processed first. This is due to the above note with the changes being batched - the trigger will only see the "last" change made and use that for the order it processes them in
40
+
41
+
See [Work with change tracking](/sql/relational-databases/track-changes/work-with-change-tracking-sql-server) for more information on change tracking and how it's used by applications such as Azure SQL triggers.
42
+
43
+
## Example usage
25
44
26
45
More samples for the Azure SQL trigger are available in the [GitHub repository](https://github.com/Azure/azure-functions-sql-extension/tree/main/samples/samples-csharp).
27
46
@@ -88,48 +107,30 @@ Isolated worker process isn't currently supported.
88
107
-->
89
108
---
90
109
91
-
92
-
::: zone-end
93
-
94
-
::: zone pivot="programming-language-java,programming-language-powershell,programming-language-javascript,programming-language-python"
95
-
96
-
> [!NOTE]
97
-
> In the current preview, Azure SQL triggers are only supported by [C# class library functions](functions-dotnet-class-library.md)
98
-
99
-
::: zone-end
100
-
101
-
102
-
::: zone pivot="programming-language-csharp"
103
-
## Attributes
110
+
## Attributes
104
111
105
112
The [C# library](functions-dotnet-class-library.md) uses the [SqlTrigger](https://github.com/Azure/azure-functions-sql-extension/blob/main/src/TriggerBinding/SqlTriggerAttribute.cs) attribute to declare the SQL trigger on the function, which has the following properties:
106
113
107
114
| Attribute property |Description|
108
115
|---------|---------|
109
116
|**TableName**| Required. The name of the table being monitored by the trigger. |
110
-
|**ConnectionStringSetting**| Required. The name of an app setting that contains the connection string for the database which contains the table being monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](/dotnet/api/microsoft.data.sqlclient.sqlconnection.connectionstring?view=sqlclient-dotnet-core-5.&preserve-view=true#Microsoft_Data_SqlClient_SqlConnection_ConnectionString) to the Azure SQL or SQL Server instance.|
111
-
112
-
113
-
::: zone-end
117
+
|**ConnectionStringSetting**| Required. The name of an app setting that contains the connection string for the database which contains the table being monitored for changes. The connection string setting name corresponds to the application setting (in `local.settings.json` for local development) that contains the [connection string](/dotnet/api/microsoft.data.sqlclient.sqlconnection.connectionstring?view=sqlclient-dotnet-core-5.&preserve-view=true#Microsoft_Data_SqlClient_SqlConnection_ConnectionString) to the Azure SQL or SQL Server instance.|
114
118
115
119
## Configuration
116
120
117
121
<!-- ### for another day ###
118
-
::: zone pivot="programming-language-java,programming-language-powershell,programming-language-javascript,programming-language-python"
119
-
120
122
121
123
The following table explains the binding configuration properties that you set in the function.json file.
122
124
123
125
|function.json property | Description|
124
126
125
-
::: zone-end -->
126
-
127
+
-->
127
128
128
129
In addition to the required ConnectionStringSetting [application setting](./functions-how-to-use-azure-function-app-settings.md#settings), the following optional settings can be configured for the SQL trigger:
129
130
130
131
| App Setting | Description|
131
132
|---------|---------|
132
-
|**Sql_Trigger_BatchSize**|This controls the number of changes processed at once before being sent to the triggered function. The default value is 100.|
133
+
|**Sql_Trigger_BatchSize**|This controls the maximum number of changes processed with each iteration of the trigger loop before being sent to the triggered function. The default value is 100.|
133
134
|**Sql_Trigger_PollingIntervalMs**|This controls the delay in milliseconds between processing each batch of changes. The default value is 1000 (1 second).|
134
135
|**Sql_Trigger_MaxChangesPerWorker**|This controls the upper limit on the number of pending changes in the user table that are allowed per application-worker. If the count of changes exceeds this limit, it may result in a scale out. The setting only applies for Azure Function Apps with [runtime driven scaling enabled](#enable-runtime-driven-scaling). The default value is 1000.|
135
136
@@ -138,7 +139,7 @@ In addition to the required ConnectionStringSetting [application setting](./func
138
139
139
140
## Set up change tracking (required)
140
141
141
-
Setting up change tracking for use with the Azure SQL trigger requires two steps. These steps can be completed from any SQL tool that supports running queries, including [VS Code](/sql/tools/visual-studio-code/mssql-extensions), [Azure Data Studio](/sql/azure-data-studio/download-azure-data-studio) or [SQL Server Management Studio](/sql/ssms/download-sql-server-management-studio-ssms).
142
+
Setting up change tracking for use with the Azure SQL trigger requires two steps. These steps can be completed from any SQL tool that supports running queries, including [Visual Studio Code](/sql/tools/visual-studio-code/mssql-extensions), [Azure Data Studio](/sql/azure-data-studio/download-azure-data-studio) or [SQL Server Management Studio](/sql/ssms/download-sql-server-management-studio-ssms).
142
143
143
144
1. Enable change tracking on the SQL database, substituting `your database name` with the name of the database where the table to be monitored is located:
144
145
@@ -166,12 +167,21 @@ Setting up change tracking for use with the Azure SQL trigger requires two steps
166
167
167
168
## Enable runtime-driven scaling
168
169
169
-
Optionally, your functions can scale automatically based on the amount of changes that are pending to be processed in the user table. To allow your functions to scale properly on the Premium plan when using SQL triggers, you need to enable runtime scale monitoring.
170
+
Optionally, your functions can scale automatically based on the number of changes that are pending to be processed in the user table. To allow your functions to scale properly on the Premium plan when using SQL triggers, you need to enable runtime scale monitoring.
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-bindings-azure-sql.md
+11-17Lines changed: 11 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,7 +27,7 @@ This set of articles explains how to work with [Azure SQL](/azure/azure-sql/inde
27
27
28
28
## Install extension
29
29
30
-
The extension NuGet package you install depends on the C# mode you're using in your function app:
30
+
The extension NuGet package you install depends on the C# mode you're using in your function app:
31
31
32
32
# [In-process](#tab/in-process)
33
33
@@ -59,15 +59,15 @@ You can install this version of the extension in your function app by registerin
59
59
60
60
---
61
61
62
-
::: zone-end
62
+
::: zone-end
63
63
64
64
65
65
::: zone pivot="programming-language-javascript, programming-language-powershell"
66
66
67
67
68
-
## Install bundle
68
+
## Install bundle
69
69
70
-
The SQL bindings extension is part of a preview [extension bundle], which is specified in your host.json project file.
70
+
The SQL bindings extension is part of a preview [extension bundle], which is specified in your host.json project file.
71
71
72
72
73
73
# [Preview Bundle v4.x](#tab/extensionv4)
@@ -93,7 +93,7 @@ Azure SQL bindings for Azure Functions aren't available for the v3 version of th
93
93
::: zone-end
94
94
95
95
96
-
::: zone pivot="programming-language-python"
96
+
::: zone pivot="programming-language-python"
97
97
98
98
## Functions runtime
99
99
@@ -103,7 +103,7 @@ Azure SQL bindings for Azure Functions aren't available for the v3 version of th
103
103
104
104
## Install bundle
105
105
106
-
The SQL bindings extension is part of a preview [extension bundle], which is specified in your host.json project file.
106
+
The SQL bindings extension is part of a preview [extension bundle], which is specified in your host.json project file.
107
107
108
108
# [Preview Bundle v4.x](#tab/extensionv4)
109
109
@@ -125,15 +125,9 @@ Azure SQL bindings for Azure Functions aren't available for the v3 version of th
125
125
126
126
---
127
127
128
-
## Update packages
129
-
130
-
Support for the SQL bindings extension is available in the 1.11.3b1 version of the [Azure Functions Python library](https://pypi.org/project/azure-functions/). Add this version of the library to your functions project with an update to the line for `azure-functions==` in the `requirements.txt` file in your Python Azure Functions project as seen in the following snippet:
131
-
132
-
```
133
-
azure-functions==1.11.3b1
134
-
```
128
+
## Configure Python Worker
135
129
136
-
Following setting the library version, update your application settings to [isolate the dependencies](./functions-app-settings.md#python_isolate_worker_dependencies) by adding `PYTHON_ISOLATE_WORKER_DEPENDENCIES` with the value `1` to your application settings. Locally, this is set in the `local.settings.json` file as seen below:
130
+
Currently, you will need to update your application settings to [isolate the dependencies](./functions-app-settings.md#python_isolate_worker_dependencies) by adding `PYTHON_ISOLATE_WORKER_DEPENDENCIES` with the value `1` to your application settings. Locally, this is set in the `local.settings.json` file as seen below:
137
131
138
132
```json
139
133
"PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1"
@@ -145,12 +139,12 @@ Support for Python durable functions with SQL bindings isn't yet available.
145
139
::: zone-end
146
140
147
141
148
-
::: zone pivot="programming-language-java"
142
+
::: zone pivot="programming-language-java"
149
143
150
144
151
145
## Install bundle
152
146
153
-
The SQL bindings extension is part of a preview [extension bundle], which is specified in your host.json project file.
147
+
The SQL bindings extension is part of a preview [extension bundle], which is specified in your host.json project file.
154
148
155
149
# [Preview Bundle v4.x](#tab/extensionv4)
156
150
@@ -188,7 +182,7 @@ Add the Java library for SQL bindings to your functions project with an update t
188
182
189
183
## SQL connection string
190
184
191
-
Azure SQL bindings for Azure Functions have a required property for connection string on both [input](./functions-bindings-azure-sql-input.md) and [output](./functions-bindings-azure-sql-output.md) bindings. SQL bindings passes the connection string to the Microsoft.Data.SqlClient library and supports the connection string as defined in the [SqlClient ConnectionString documentation](/dotnet/api/microsoft.data.sqlclient.sqlconnection.connectionstring?view=sqlclient-dotnet-core-5.0&preserve-view=true#Microsoft_Data_SqlClient_SqlConnection_ConnectionString). Notable keywords include:
185
+
Azure SQL bindings for Azure Functions have a required property for the connection string on all bindings and triggers. These pass the connection string to the Microsoft.Data.SqlClient library and supports the connection string as defined in the [SqlClient ConnectionString documentation](/dotnet/api/microsoft.data.sqlclient.sqlconnection.connectionstring?view=sqlclient-dotnet-core-5.0&preserve-view=true#Microsoft_Data_SqlClient_SqlConnection_ConnectionString). Notable keywords include:
192
186
193
187
-`Authentication` allows a function to connect to Azure SQL with Azure Active Directory, including [Active Directory Managed Identity](./functions-identity-access-azure-sql-with-managed-identity.md)
194
188
-`Command Timeout` allows a function to wait for specified amount of time in seconds before terminating a query (default 30 seconds)
0 commit comments