This set of articles explains how to work with Azure SQL bindings in Azure Functions. Azure Functions supports input bindings, output bindings, and a function trigger for the Azure SQL and SQL Server products.
Install extensionThe extension NuGet package you install depends on the C# mode you're using in your function app:
Functions execute in an isolated C# worker process. To learn more, see Guide for running C# Azure Functions in an isolated worker process.
Add the extension to your project by installing this NuGet package.
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Sql
To use a preview version of the Microsoft.Azure.Functions.Worker.Extensions.Sql package, add the --prerelease
flag to the command. You can view preview functionality on the Azure Functions SQL Extensions release page.
dotnet add package Microsoft.Azure.Functions.Worker.Extensions.Sql --prerelease
Note
Breaking changes between preview releases of the Azure SQL bindings for Azure Functions requires that all Functions targeting the same database use the same version of the SQL extension package.
Functions execute in the same process as the Functions host. To learn more, see Develop C# class library functions using Azure Functions.
Add the extension to your project by installing this NuGet package.
dotnet add package Microsoft.Azure.WebJobs.Extensions.Sql
To use a preview version of the Microsoft.Azure.WebJobs.Extensions.Sql package, add the --prerelease
flag to the command. You can view preview functionality on the Azure Functions SQL Extensions release page.
dotnet add package Microsoft.Azure.WebJobs.Extensions.Sql --prerelease
Note
Breaking changes between preview releases of the Azure SQL bindings for Azure Functions requires that all Functions targeting the same database use the same version of the SQL extension package.
Install bundleThe SQL bindings extension is part of the v4 extension bundle, which is specified in your host.json project file.
The extension bundle is specified by the following code in your host.json
file:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
You can use the preview extension bundle by adding or replacing the following code in your host.json
file:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
"version": "[4.*, 5.0.0)"
}
}
You can view preview functionality on the Azure Functions SQL Extensions release page.
Note
Breaking changes between preview releases of the Azure SQL bindings for Azure Functions requires that all Functions targeting the same database use the same version of the SQL extension package.
Functions runtime Install bundleThe SQL bindings extension is part of the v4 extension bundle, which is specified in your host.json project file.
The extension bundle is specified by the following code in your host.json
file:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
You can use the preview extension bundle by adding or replacing the following code in your host.json
file:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
"version": "[4.*, 5.0.0)"
}
}
You can view preview functionality on the Azure Functions SQL Extensions release page.
Note
Breaking changes between preview releases of the Azure SQL bindings for Azure Functions requires that all Functions targeting the same database use the same version of the SQL extension package.
Install bundleThe SQL bindings extension is part of the v4 extension bundle, which is specified in your host.json project file.
The extension bundle is specified by the following code in your host.json
file:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.*, 5.0.0)"
}
}
You can use the preview extension bundle by adding or replacing the following code in your host.json
file:
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Preview",
"version": "[4.*, 5.0.0)"
}
}
You can view preview functionality on the Azure Functions SQL Extensions release page.
Note
Breaking changes between preview releases of the Azure SQL bindings for Azure Functions requires that all Functions targeting the same database use the same version of the SQL extension package.
Update packagesAdd the Java library for SQL bindings to your functions project with an update to the pom.xml
file in your Java Azure Functions project as seen in the following snippet:
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library-sql</artifactId>
<version>2.1.0</version>
</dependency>
You can use the preview extension bundle with an update to the pom.xml
file in your Java Azure Functions project as seen in the following snippet:
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library-sql</artifactId>
<version>2.1.0-preview</version>
</dependency>
SQL connection string
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.
Important
For optimal security, you should use Microsoft Entra ID with managed identities for connections between Functions and Azure SQL Database. Managed identities make your app more secure by eliminating secrets from your application deployments, such as credentials in the connection strings, server names, and ports being used. You can learn how to use managed identities in this tutorial, Connect a function app to Azure SQL with managed identity and SQL bindings.
Notable keywords include:
Authentication
: allows a function to connect to Azure SQL with Microsoft Entra ID and managed identities. For more information, see Connect a function app to Azure SQL with managed identity and SQL bindings.Command timeout
: allows a function to wait for specified amount of time in seconds before terminating a query (default 30 seconds)ConnectRetryCount
: allows a function to automatically make additional reconnection attempts, especially applicable to Azure SQL Database serverless tier (default 1)Pooling
: allows a function to reuse connections to the database, which can improve performance (default true
). Additional settings for connection pooling include Connection Lifetime
, Max Pool Size
, and Min Pool Size
. Learn more about connection pooling in the ADO.NET documentationNTEXT
, TEXT
, or IMAGE
aren't supported and data upserts will fail. These types will be removed in a future version of SQL Server and aren't compatible with the OPENJSON
function used by this Azure Functions binding.In addition to the samples for C#, Java, JavaScript, PowerShell, and Python available in the Azure SQL bindings GitHub repository, more are available in Azure Samples:
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4