Düzenle

Aracılığıyla paylaş


Create Azure Functions with the SQL bindings extension through the Object Explorer

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics

Overview

Microsoft SQL Bindings for VS Code enable users to develop Azure Functions with Azure SQL bindings, see further documentation here. Install the VS Code extension here.

From the Object Explorer

To create an Azure Function from a specific Table or View in object explorer (OE), right-click on a table or view from a connected server in SQL Server object explorer and select Create Azure Function with SQL Binding.

Table OE Command: Screenshot of object explorer context menu to add a SQL binding from Table.

View OE Command: Screenshot of object explorer context menu to add a SQL binding from View.

If you haven't yet created the Azure Function project, a VS Code prompt will appear to aid in creating a new Azure Function project.

Screenshot of VS Code notification to create a new Azure Function project since none were found in folder.

The extension will then ask you to select the folder where you want to create the Azure Function.

Screenshot of a prompt to choose folder to create Azure Function with SQL binding to.

If you're creating an Azure Function with SQL binding from a table, the extension will prompt you to select the binding type to use, either an Input (Retrieves data from a database) or Output (Save data to a database) binding.

Note

Azure Function with SQL Binding from a View is only supported for Input bindings.

Screenshot of a prompt to select binding type.

The extension will then prompt you to enter the function name to be used for the Azure Function.

Screenshot of a prompt to enter function name.

If you already have connection strings stored in the local.settings.json, then the extension will prompt you to select the connection string to use for the Azure Function or create a new connection string.

Screenshot of a prompt to select connection string setting.

If you select Create new local app setting, then the extension will prompt you to enter the connection string name and value.

Screenshot of a pPrompt to enter connection string.

If you're creating the Azure Function with SQL Binding to an existing Azure Function project, then the extension will prompt you whether you would like to include the password for the connection string in the local.settings.json file.

Screenshot of a prompt to save the password to the SQL connection string.

If Yes, then the password will be saved to the local.settings.json file. If No then the extension will warn you that the password won't be saved to the local.settings.json file (shown below), and you'll need to manually add the password later to the local.settings.json file.

Screenshot of a warning to add password to SQL connection string later manually.

The extension will then prompt you to provide the namespace for the Azure Function.

Screenshot of a prompt for namespace for the Azure Function.

If you're creating a brand new Azure Function project with SQL binding, then the extension will prompt whether you would like to include the password for the connection string in the local.settings.json file.

A progress notification will appear to indicate that the Azure Function has completed.

Screenshot of a information message indicating finished creating Azure Function Project.

Once the Azure Function is created, the extension will generate the code either for an Input or Output binding shown here.

Next steps