Azure SQL bindings for Azure Functions overview (preview)
Note
The Azure SQL trigger is only supported on Premium and Dedicated plans. Consumption is not supported. Azure SQL input/output bindings are supported for all plans.
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.
Action | Type |
---|---|
Trigger a function when a change is detected on a SQL table | SQL trigger |
Read data from a database | Input binding |
Save data to a database | Output binding |
Install extension
The extension NuGet package you install depends on the C# mode you're using in your function app:
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 --prerelease
Install bundle
The SQL bindings extension is part of a preview extension bundle, which is specified in your host.json project file.
You can add 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)"
}
}
Functions runtime
Note
Python language support for the SQL bindings extension is available starting with v4.5.0 of the functions runtime. You may need to update your install of Azure Functions Core Tools for local development.
Install bundle
The SQL bindings extension is part of a preview extension bundle, which is specified in your host.json project file.
You can add 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)"
}
}
Install bundle
The SQL bindings extension is part of a preview extension bundle, which is specified in your host.json project file.
You can add 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)"
}
}
Update packages
Add the Java library for SQL bindings to your functions project with an update to the pom.xml
file in your Python Azure Functions project as seen in the following snippet:
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library-sql</artifactId>
<version>0.1.1</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. Notable keywords include:
Authentication
allows a function to connect to Azure SQL with Azure Active Directory, including Active Directory Managed IdentityCommand 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)
Considerations
- Azure SQL binding supports version 4.x and later of the Functions runtime.
- Source code for the Azure SQL bindings can be found in this GitHub repository.
- This binding requires connectivity to an Azure SQL or SQL Server database.
- Output bindings against tables with columns of data types
NTEXT
,TEXT
, orIMAGE
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 theOPENJSON
function used by this Azure Functions binding.
Next steps
- Read data from a database (Input binding)
- Save data to a database (Output binding)
- Run a function when data is changed in a SQL table (Trigger)
- Review ToDo API sample with Azure SQL bindings
- Learn how to connect Azure Function to Azure SQL with managed identity
- Use SQL bindings in Azure Stream Analytics
Feedback
Submit and view feedback for