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
Copy file name to clipboardExpand all lines: articles/azure-functions/functions-add-output-binding-azure-sql-vs-code.md
+12-78Lines changed: 12 additions & 78 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
---
2
2
title: Connect Azure Functions to Azure SQL Database using Visual Studio Code
3
3
description: Learn how to connect Azure Functions to Azure SQL Database by adding an output binding to your Visual Studio Code project.
4
-
ms.date: 03/04/2024
4
+
ms.date: 04/25/2024
5
5
ms.topic: quickstart
6
6
author: dzsquared
7
7
ms.author: drskwier
@@ -30,11 +30,6 @@ Before you begin, you must complete the [quickstart: Create a Python function in
30
30
31
31
More details on the settings for [Azure SQL bindings and trigger for Azure Functions](functions-bindings-azure-sql.md) are available in the Azure Functions documentation.
32
32
33
-
::: zone pivot="programming-language-javascript"
34
-
>[!NOTE]
35
-
>This article currently only supports [Node.js v3 for Functions](./functions-reference-node.md?pivots=nodejs-model-v3).
36
-
::: zone-end
37
-
38
33
## Create your Azure SQL Database
39
34
40
35
1. Follow the [Azure SQL Database create quickstart](/azure/azure-sql/database/single-database-create-quickstart) to create a serverless Azure SQL Database. The database can be empty or created from the sample dataset AdventureWorksLT.
@@ -105,15 +100,9 @@ Your project has been configured to use [extension bundles](functions-bindings-r
105
100
106
101
Extension bundles usage is enabled in the host.json file at the root of the project, which appears as follows:
@@ -149,33 +138,15 @@ using Microsoft.Azure.Functions.Worker.Extensions.Sql;
149
138
```
150
139
::: zone-end
151
140
::: zone pivot="programming-language-javascript"
152
-
Binding attributes are defined directly in the function.json file. Depending on the binding type, additional properties may be required. The [Azure SQL output configuration](./functions-bindings-azure-sql-output.md#configuration) describes the fields required for an Azure SQL output binding.
153
-
154
-
<!--The extension makes it easy to add bindings to the function.json file.
155
-
156
-
To create a binding, right-click (Ctrl+click on macOS) the `function.json` file in your HttpTrigger folder and choose **Add binding...**. Follow the prompts to define the following binding properties for the new binding:
141
+
Binding attributes are defined directly in your code. The [Azure SQL output configuration](./functions-bindings-azure-sql-output.md#configuration) describes the fields required for an Azure SQL output binding.
157
142
158
-
| Prompt | Value | Description |
159
-
| -------- | ----- | ----------- |
160
-
| **Select binding direction** | `out` | The binding is an output binding. |
161
-
| **Select binding with direction "out"** | `Azure SQL` | The binding is an Azure SQL binding. |
162
-
| **The name used to identify this binding in your code** | `toDoItems` | Name that identifies the binding parameter referenced in your code. |
163
-
| **The Azure SQL table where data will be written** | `dbo.ToDo` | The name of the Azure SQL table. |
164
-
| **Select setting from "local.setting.json"** | `SqlConnectionString` | The name of an application setting that contains the connection string for the Azure SQL database. |
143
+
For this `MultiResponse` scenario, you need to add an `extraOutputs` output binding to the function.
165
144
166
-
A binding is added to the `bindings` array in your function.json, which should look like the following after removing any `undefined` values present. -->
@@ -228,20 +199,9 @@ public static OutputType Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "
228
199
229
200
::: zone-end
230
201
::: zone pivot="programming-language-javascript"
202
+
Add code that uses the `extraInputs` output binding object on `context` to send a JSON document to the named output binding function, `sendToSql`. Add this code before the `return` statement.
231
203
232
-
Add code that uses the `toDoItems` output binding object on `context.bindings` to create a new item in the `dbo.ToDo` table. Add this code before the `context.res` statement.
::: zone pivot="programming-language-javascript,programming-language-python"
105
+
106
+
::: zone pivot="programming-language-javascript"
107
+
108
+
Your project has been configured to use [extension bundles](functions-bindings-register.md#extension-bundles), which automatically installs a predefined set of extension packages.
109
+
110
+
Extension bundles usage is enabled in the *host.json* file at the root of the project, which appears as follows:
Your project has been configured to use [extension bundles](functions-bindings-register.md#extension-bundles), which automatically installs a predefined set of extension packages.
108
119
@@ -128,35 +139,15 @@ The `MultiResponse` class allows you to both write to the specified collection i
128
139
Specific attributes specify the name of the container and the name of its parent database. The connection string for your Azure Cosmos DB account is set by the `CosmosDbConnectionSetting`.
129
140
::: zone-end
130
141
::: zone pivot="programming-language-javascript"
131
-
Binding attributes are defined directly in the *function.json* file. Depending on the binding type, other properties may be required. The [Azure Cosmos DB output configuration](./functions-bindings-cosmosdb-v2-output.md#configuration) describes the fields required for an Azure Cosmos DB output binding. The extension makes it easy to add bindings to the *function.json* file.
132
-
133
-
To create a binding, right-click (Ctrl+select on macOS) the *function.json* file in your HttpTrigger folder and choose **Add binding...**. Follow the prompts to define the following binding properties for the new binding:
134
-
135
-
| Prompt | Value | Description |
136
-
| -------- | ----- | ----------- |
137
-
|**Select binding direction**|`out`| The binding is an output binding. |
138
-
|**Select binding with direction "out"**|`Azure Cosmos DB`| The binding is an Azure Cosmos DB binding. |
139
-
|**The name used to identify this binding in your code**|`outputDocument`| Name that identifies the binding parameter referenced in your code. |
140
-
|**The Azure Cosmos DB database where data will be written**|`my-database`| The name of the Azure Cosmos DB database containing the target container. |
141
-
|**Database collection where data will be written**|`my-container`| The name of the Azure Cosmos DB container where the JSON documents will be written. |
142
-
|**If true, creates the Azure Cosmos DB database and collection**|`false`| The target database and container already exist. |
143
-
|**Select setting from "local.setting.json"**|`CosmosDbConnectionSetting`| The name of an application setting that contains the connection string for the Azure Cosmos DB account. |
144
-
|**Partition key (optional)**|*leave blank*| Only required when the output binding creates the container. |
145
-
|**Collection throughput (optional)**|*leave blank*| Only required when the output binding creates the container. |
146
-
147
-
A binding is added to the `bindings` array in your *function.json*, which should look like the following after removing any `undefined` values present:
148
-
149
-
```json
150
-
{
151
-
"type": "cosmosDB",
152
-
"direction": "out",
153
-
"name": "outputDocument",
154
-
"databaseName": "my-database",
155
-
"containerName": "my-container",
156
-
"createIfNotExists": "false",
157
-
"connection": "CosmosDbConnectionSetting"
158
-
}
159
-
```
142
+
Binding attributes are defined directly in your function code. The [Azure Cosmos DB output configuration](./functions-bindings-cosmosdb-v2-output.md#configuration) describes the fields required for an Azure Cosmos DB output binding.
143
+
144
+
For this `MultiResponse` scenario, you need to add an `extraOutputs` output binding to the function.
@@ -179,43 +170,13 @@ Replace the existing Run method with the following code:
179
170
180
171
::: zone-end
181
172
::: zone pivot="programming-language-javascript"
182
-
Add code that uses the `outputDocument` output binding object on `context.bindings` to create a JSON document. Add this code before the `context.res` statement.
Add code that uses the `extraInputs` output binding object on `context` to send a JSON document to the named output binding function, `sendToCosmosDb`. Add this code before the `return` statement.
In this article, you integrate an Azure Storage queue with the function and storage account you created in the previous quickstart article. You achieve this integration by using an *output binding* that writes data from an HTTP request to a message in the queue. Completing this article incurs no additional costs beyond the few USD cents of the previous quickstart. To learn more about bindings, see [Azure Functions triggers and bindings concepts](functions-triggers-bindings.md).
15
15
16
-
::: zone pivot="programming-language-javascript"
17
-
>[!NOTE]
18
-
>This article currently only supports [Node.js v3 for Functions](./functions-reference-node.md?pivots=nodejs-model-v3).
19
-
::: zone-end
20
-
21
16
## Configure your local environment
22
17
23
18
::: zone pivot="programming-language-csharp"
@@ -66,12 +61,13 @@ With the queue binding defined, you can now update your function to receive the
0 commit comments