Create Azure Functions with the SQL bindings extension through the Object Explorer for Visual Studio Code
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 Command Palette
Run the MS SQL: Create Azure Function with SQL Binding
command from the command palette to create a new function with a SQL binding.
The extension will then prompt you to select the object type to insert (Input binding
) or upsert into (Output binding
), either a Table
or View
.
Then the extension will prompt you to select a connection profile to use for the Azure Function or create a connection profile.
Once you either select a connection profile or create a new connection profile, the extension will prompt you to select the database from the selected connection to use for the Azure Function.
Once you select a database, the extension will prompt you to select a table, or view to use or to enter a table or view to query or upsert into. This prompt is based on the object type you selected earlier.
Note
Azure Function with SQL Binding from a View
is only supported for Input
bindings.
Prompt for Table:
Prompt for View:
The extension will then prompt you to enter the function name to be used for the Azure Function.
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.
If you select Create new local app setting
, then the extension will prompt you to enter the connection string name and value.
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.
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.
The extension will then prompt you to provide the 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.
Once the Azure Function is created, the extension will generate the code either for an Input
or Output
binding shown here.
In an existing Azure Function
Open the C# Azure Function in an editor and then run the MS SQL: Add SQL Binding
command from the command palette to add a SQL binding to an existing function.
The extension will then prompt you to select Azure function in the current file to add the 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.
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.
If you select Create new local app setting
, then the extension will prompt you to enter the connection string name and value.
The extension will then prompt you to select a connection string method to select a connection profile or enter a connection string to use for the SQL binding.
If you decide to select a connection profile, the extension will prompt you to select the database from the selected connection to use for the Azure Function.
Once you select a database, the extension will prompt you to select a table to use, or to enter a table or view to query or upsert into.
Prompt for Table:
The extension will then prompt you whether you would like to include the password for the connection string in the local.settings.json file.
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.
Once the Azure Function is created, the extension will generate the code either for an Input
or Output
binding shown here.