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.

Screenshot of a VS Code command palette command `MS SQL: Create Azure Function with SQL Binding (preview).

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.

Screenshot of a prompt to select the object type.

Then the extension will prompt you to select a connection profile to use for the Azure Function or create a connection profile.

Screenshot of a prompt for 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.

Screenshot of a prompt for database

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: Screenshot of a prompt for table.

Prompt for View: Screenshot of a prompt for view.

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

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.

Screenshot of a VS Code command palette command `MS SQL: Add SQL Binding (preview).

The extension will then prompt you to select Azure function in the current file to add the SQL binding to. Screenshot of Azure Functions found in project.

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.

Screenshot of a prompt to select or create a new 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 prompt to enter connection string.

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.

Screenshot of a prompt to select connection string setting method.

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.

Screenshot of a prompt for database.

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: Screenshot of a 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.

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.

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

Next steps