Create Azure Functions with the SQL Bindings extension for Visual Studio Code through the Command Palette
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Overview
Microsoft SQL Bindings for Visual Studio Code enable users to develop Azure Functions with Azure SQL bindings. For more information, see Create Azure Functions with the SQL Bindings extension for Visual Studio Code. To install the extension, see SQL Bindings extension for Visual Studio Code.
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 then prompts you to select the object type to insert (Input binding
) or upsert into (Output binding
), either a Table
or View
.
Then the extension prompts 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 prompts you to select the database from the selected connection to use for the Azure Function.
Once you select a database, the extension prompts 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 then prompts 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 prompts 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 prompts 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 prompts you whether you would like to include the password for the connection string in the local.settings.json
file.
If Yes
, then the password is saved to the local.settings.json
file. If No
then the extension warns you that the password won't be saved to the local.settings.json
file (shown here), and you need to manually add the password later to the local.settings.json
file.
The extension then prompts 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 prompts whether you would like to include the password for the connection string in the local.settings.json
file.
A progress notification appears to indicate that the Azure Function has completed.
Once the Azure Function is created, the extension generates the code either for an Input
or Output
binding. For more information, see Generated code for Azure functions with SQL bindings.
Open an 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 then prompts 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 prompts 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 prompts 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 prompts you to enter the connection string name and value.
The extension then prompts 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 prompts you to select the database from the selected connection to use for the Azure Function.
Once you select a database, the extension prompts you to select a table to use, or to enter a table or view to query or upsert into.
Prompt for Table:
The extension then prompts you whether you would like to include the password for the connection string in the local.settings.json
file.
If Yes
, then the password is saved to the local.settings.json
file. If No
then the extension warns you that the password won't be saved to the local.settings.json
file (shown here), and you need to manually add the password later to the local.settings.json
file.
Once the Azure Function is created, the extension generates the code either for an Input
or Output
binding. For more information, see Generated code for Azure functions with SQL bindings.