This repo contains a sample project created with Azure Core Tools and Visual Studio Code.
- Install Azure CLI
- Install .Net Core 3.1
- Install Azure Functions Core Tools
- Install Visual Studio Code
- Install Azure Functions VS Code extension
- Install C# VS Code Extension
This project contains a CRUD for SQL Server DB using functions for each operation. In order to run locally the project you should configure a DB with a simple table that will contains 4 columns.
At your SQL Server instance, create a new DB and create a simple table that will contains 4 columns: id, name, description and enabled. You can use the following SQL Server Script:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Departments](
[id] [int] IDENTITY(1,1) NOT NULL,
[name] [varchar](255) NOT NULL,
[description] [varchar](255) NOT NULL,
[enabled] [bit] NOT NULL DEFAULT 1
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Departments] ADD PRIMARY KEY CLUSTERED
(
[id] ASC
)WITH (STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
GO
Be sure that in your local environment you have the fille local.settings.json. Within that file you should add the connection string, like this sample:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
},
"ConnectionString": "<Your Connection String>"
}
You can run the project with VS Code. Open the folder with VS Code, go to options panel at the top and click in "Run" then you can select "Start debugging" or "Run without debugging".
For reference check my sesion in Code Camp 2021 at Youtube.
In order to run your Function in the cloud, you should create an Azure Function App instance. You can create it within Visual Studio code using the Azure Functions plugin.
Once your Function App instance is created, now you can deploy it with Visual Studio Code using the Azure Functions plugin.
For more information you can check the official documentation
Go to your Azure App Function in Azure and add an environment variable at the instance's Settings -> Configuration -> Application settings.
- Name: ConnectionString
- Value: < Your Connection String >
After add the connection string, save changes.