Skip to content

Commit 26727b5

Browse files
Merge pull request #226739 from Charles-Gagnon/chgagnon/updateSqlBindingDocs
Update SQL binding docs
2 parents 5cb8863 + ff74e80 commit 26727b5

File tree

2 files changed

+50
-46
lines changed

2 files changed

+50
-46
lines changed

articles/azure-functions/functions-bindings-azure-sql-trigger.md

Lines changed: 39 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,36 @@ zone_pivot_groups: programming-languages-set-functions-lang-workers
1111

1212
# Azure SQL trigger for Functions (preview)
1313

14+
::: zone pivot="programming-language-csharp"
15+
1416
> [!NOTE]
15-
> 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.
1618
1719
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.
1820

1921
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).
2022

21-
## Example usage
22-
<a id="example"></a>
23+
## Functionality Overview
2324

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
2544

2645
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).
2746

@@ -88,48 +107,30 @@ Isolated worker process isn't currently supported.
88107
-->
89108
---
90109

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
104111

105112
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:
106113

107114
| Attribute property |Description|
108115
|---------|---------|
109116
| **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.|
114118

115119
## Configuration
116120

117121
<!-- ### for another day ###
118-
::: zone pivot="programming-language-java,programming-language-powershell,programming-language-javascript,programming-language-python"
119-
120122
121123
The following table explains the binding configuration properties that you set in the function.json file.
122124
123125
|function.json property | Description|
124126
125-
::: zone-end -->
126-
127+
-->
127128

128129
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:
129130

130131
| App Setting | Description|
131132
|---------|---------|
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.|
133134
|**Sql_Trigger_PollingIntervalMs**|This controls the delay in milliseconds between processing each batch of changes. The default value is 1000 (1 second).|
134135
|**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.|
135136

@@ -138,7 +139,7 @@ In addition to the required ConnectionStringSetting [application setting](./func
138139

139140
## Set up change tracking (required)
140141

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).
142143

143144
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:
144145

@@ -166,12 +167,21 @@ Setting up change tracking for use with the Azure SQL trigger requires two steps
166167
167168
## Enable runtime-driven scaling
168169
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.
170171
171172
[!INCLUDE [functions-runtime-scaling](../../includes/functions-runtime-scaling.md)]
172173
173174
174175
## Next steps
175176
176177
- [Read data from a database (Input binding)](./functions-bindings-azure-sql-input.md)
177-
- [Save data to a database (Output binding)](./functions-bindings-azure-sql-output.md)
178+
- [Save data to a database (Output binding)](./functions-bindings-azure-sql-output.md)
179+
180+
::: zone-end
181+
182+
::: zone pivot="programming-language-java,programming-language-powershell,programming-language-javascript,programming-language-python"
183+
184+
> [!NOTE]
185+
> In the current preview, Azure SQL triggers are only supported by [C# class library functions](functions-dotnet-class-library.md)
186+
187+
::: zone-end

articles/azure-functions/functions-bindings-azure-sql.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ This set of articles explains how to work with [Azure SQL](/azure/azure-sql/inde
2727

2828
## Install extension
2929

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:
3131

3232
# [In-process](#tab/in-process)
3333

@@ -59,15 +59,15 @@ You can install this version of the extension in your function app by registerin
5959

6060
---
6161

62-
::: zone-end
62+
::: zone-end
6363

6464

6565
::: zone pivot="programming-language-javascript, programming-language-powershell"
6666

6767

68-
## Install bundle
68+
## Install bundle
6969

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.
7171

7272

7373
# [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
9393
::: zone-end
9494

9595

96-
::: zone pivot="programming-language-python"
96+
::: zone pivot="programming-language-python"
9797

9898
## Functions runtime
9999

@@ -103,7 +103,7 @@ Azure SQL bindings for Azure Functions aren't available for the v3 version of th
103103

104104
## Install bundle
105105

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.
107107

108108
# [Preview Bundle v4.x](#tab/extensionv4)
109109

@@ -125,15 +125,9 @@ Azure SQL bindings for Azure Functions aren't available for the v3 version of th
125125

126126
---
127127

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
135129

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:
137131

138132
```json
139133
"PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1"
@@ -145,12 +139,12 @@ Support for Python durable functions with SQL bindings isn't yet available.
145139
::: zone-end
146140

147141

148-
::: zone pivot="programming-language-java"
142+
::: zone pivot="programming-language-java"
149143

150144

151145
## Install bundle
152146

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.
154148

155149
# [Preview Bundle v4.x](#tab/extensionv4)
156150

@@ -188,7 +182,7 @@ Add the Java library for SQL bindings to your functions project with an update t
188182

189183
## SQL connection string
190184

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:
192186

193187
- `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)
194188
- `Command Timeout` allows a function to wait for specified amount of time in seconds before terminating a query (default 30 seconds)

0 commit comments

Comments
 (0)