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. Learn more about determining the runtime in Azure regions from the functions runtime documentation. Please see the tracking GitHub issue for the latest update on availability.

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

Support for the SQL bindings extension is available in the 1.11.3b1 version of the Azure Functions Python library. 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:

azure-functions==1.11.3b1

Following setting the library version, update your application settings to isolate the 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:

"PYTHON_ISOLATE_WORKER_DEPENDENCIES": "1"

Support for Python durable functions with SQL bindings isn't yet available.

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 connection string on both input and output 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. Notable keywords include:

  • Authentication allows a function to connect to Azure SQL with Azure Active Directory, including Active Directory Managed Identity
  • 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)

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

Next steps