You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A primary key must be set in your SQL table before using the bindings. To do this, run the below SQL commands in the SQL query editor. Note that this step needs to only be done once. If this has already been done, you can safely proceed to [Set Up Development Environment](#set-up-development-environment).
20
-
21
-
1. Ensure there are no NULL values in the primary key column. The primary key will usually be an ID column.
22
-
23
-
```sql
24
-
ALTERTABLE [TableName] ALTER COLUMN [PrimaryKeyColumnName] intNOT NULL
25
-
```
26
-
27
-
2. Setprimary key column.
28
-
29
-
```sql
30
-
ALTER TABLE [TableName] ADD CONSTRAINT PKey PRIMARY KEY CLUSTERED ([PrimaryKeyColumn]);
31
-
```
32
-
33
-
3. Congrats on setting up your database! Now continue to set up your local environment and complete the quick start.
15
+
In order to test changes it is suggested that you have a SQL server set up to connect to and run queries against. Instructions to set this up can be found in the [Quick Start Guide](./README.md#quick-start)
34
16
35
17
### Set Up Development Environment
36
18
37
19
1.[Install VS Code](https://code.visualstudio.com/Download)
38
-
20
+
39
21
2. Clone repo and open in VS Code:
40
22
41
23
```bash
@@ -46,19 +28,6 @@ code .
46
28
3. Install extensions when prompted after VS Code opens
47
29
- Note: This includes the Azure Functions, C#, and editorconfig extensions
48
30
49
-
4. Get your SqlConnectionString.
50
-
51
-
If you provisioned an Azure SQL Database, your connection string can be found in your SQL database resource by going to the left blade and clicking 'Connection strings'. Copy the Connection String.
52
-
53
-
- (*Note: when pasting in the connection string, you will need to replace part of the connection string where it says '{your_password}' with your Azure SQL Server password*)
54
-
55
-
If your database wasn't provisioned in Azure, please follow documentation [here](https://docs.microsoft.com/sql/connect/homepage-sql-connection-programming), if you're unfamliar with how to construct a connection string.
56
-
57
-
5. In'local.settings.json'in'Values', verify you have the below. If not, add the below and replace "Your Connection String" with the your connection string from the previous step:
31
+
4. Configure the Function App located in the [samples](./samples) folder by following the instructions [here](./README.md#configure-function-app)
6. Press F5 to run SQL bindings samples that are included in this repo.
33
+
5. Press F5 to run SQL bindings samples that are included in this repo. The output window should display startup information as well as the function endpoints that were started.
Copy file name to clipboardExpand all lines: README.md
+72-63Lines changed: 72 additions & 63 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,8 +6,8 @@
6
6
7
7
This repository contains the Azure SQL binding for Azure Functions extension code as well as a quick start tutorial and samples illustrating how to use the binding in different ways. A high level explanation of the bindings is provided below. Additional information for each is in their respective sample sections.
8
8
9
-
-**input binding**: takes a SQL query to run and returns the output of the query in the function.
10
-
-**output binding**: takes a list of rows and upserts them into the user table (i.e. If a row doesn't already exist, it is added. If it does, it is updated).
9
+
-**Input Binding**: takes a SQL query to run and returns the output of the query in the function.
10
+
-**Output Binding**: takes a list of rows and upserts them into the user table (i.e. If a row doesn't already exist, it is added. If it does, it is updated).
11
11
12
12
Further information on the Azure SQL binding for Azure Functions is also available in the [Azure Functions docs](https://docs.microsoft.com/azure/azure-functions/functions-bindings-azure-sql).
13
13
@@ -17,10 +17,13 @@ Further information on the Azure SQL binding for Azure Functions is also availab
17
17
-[Introduction](#introduction)
18
18
-[Table of Contents](#table-of-contents)
19
19
-[Quick Start](#quick-start)
20
+
-[Create a SQL Server](#create-a-sql-server)
21
+
-[Docker container](#docker-container)
22
+
-[Azure SQL Database](#azure-sql-database)
20
23
-[SQL Setup](#sql-setup)
21
-
-[Set Up Local .NET Function App](#set-up-local-net-function-app)
24
+
-[Create .NET Function App](#create-net-function-app)
25
+
-[Configure Function App](#configure-function-app)
@@ -39,61 +42,105 @@ Further information on the Azure SQL binding for Azure Functions is also availab
39
42
40
43
## Quick Start
41
44
45
+
### Create a SQL Server
46
+
47
+
First you'll need a SQL server for the bindings to connect to. If you already have your own set up then you can skip this step, otherwise pick from one of the below options.
48
+
49
+
#### Docker container
50
+
51
+
SQL Server on Docker makes it easy to set up and connect to a locally hosted instance of SQL Server. Instructions for getting started can be found [here](https://docs.microsoft.com/sql/linux/sql-server-linux-docker-container-deployment).
52
+
53
+
#### Azure SQL Database
54
+
55
+
Azure SQL Database is a fully managed platform as a service (PaaS) database engine that runs the latest stable version of the Microsoft SQL Server database engine. Instructions for getting started can be found [here](https://docs.microsoft.com/azure/azure-sql/database/single-database-create-quickstart).
56
+
57
+
42
58
### SQL Setup
43
59
44
-
This requires already having a SQL database. If you need to create a SQL database, please refer to [Create Azure SQL Database](#Create-Azure-SQL-Database) in the tutorials section.
60
+
Next you'll configure your SQL Server database for use with Azure SQL binding for Azure Functions.
45
61
46
-
A primary key must be set in your SQL table before using the bindings. To do this, run the below SQL commands in the SQL query editor.
62
+
This will require connecting to and running queries - you can use [Azure Data Studio](https://docs.microsoft.com/sql/azure-data-studio/download-azure-data-studio) or the [MSSQL for VS Code Extension](https://docs.microsoft.com/sql/tools/visual-studio-code/sql-server-develop-use-vscode) to do this.
47
63
48
-
1.Ensure there are no NULL values in the primary key column. The primary key will usually be an ID column.
64
+
1.First you'll need a table to run queries against. If you already have one you'd like to use then you can skip this step.
49
65
50
-
```sql
51
-
ALTER TABLE ['your table name'] alter column ['column to be primary key'] int NOT NULL
52
-
```
66
+
Otherwise connect to your database and run the following query to create a simple table to start with.
67
+
68
+
```sql
69
+
CREATE TABLE Employees (
70
+
EmployeeId int,
71
+
FirstName varchar(255),
72
+
LastName varchar(255),
73
+
Company varchar(255),
74
+
Team varchar(255)
75
+
);
76
+
```
53
77
54
-
1. Setprimary key column.
78
+
2. Next a primary key must be set in your SQL table before using the bindings. To do this, run the queries below, replacing the placeholder values for your table and column.
79
+
80
+
```sql
81
+
ALTER TABLE ['{table_name}'] ALTER COLUMN ['{primary_key_column_name}'] int NOT NULL
82
+
83
+
ALTER TABLE ['{table_name}'] ADD CONSTRAINT PKey PRIMARY KEY CLUSTERED (['{primary_key_column_name}']);
84
+
```
55
85
56
-
```sql
57
-
ALTER TABLE ['your table name'] ADD CONSTRAINT PKey PRIMARY KEY CLUSTERED (['column to be primary key']);
58
-
```
59
86
60
-
1. Congrats on setting up your database! Now continue to set up your local environment and complete the quick start.
87
+
### Create .NET Function App
61
88
62
-
### Set Up Local .NET Function App
89
+
Now you will need a .NET Function App to add the binding to. If you have one created already you can skip this step.
63
90
64
-
These steps can be done in the Terminal/CLI or with PowerShell. Completing this section will allow you to begin using the Azure SQL binding.
91
+
These steps can be done in the Terminal/CLI or with PowerShell.
Once you have your Function App you need to configure it for use with Azure SQL bindings for Azure Functions.
114
+
82
115
1. Ensure you have Azure Storage Emulator running. This is specific to the sample functions in this repository with a non-HTTP trigger. For information on the Azure Storage Emulator, refer to the docs on its use in [functions local development](https://docs.microsoft.com/azure/azure-functions/functions-app-settings#azurewebjobsstorage) and [installation](https://docs.microsoft.com/azure/storage/common/storage-use-emulator#get-the-storage-emulator).
83
116
84
-
1. Get your SqlConnectionString. Your connection string can be found in your SQL database resource by going to the left blade and clicking 'Connection strings'. Copy the Connection String.
117
+
1. Get your SQL connection string
118
+
119
+
<details>
120
+
<summary>Local SQL Server</summary>
121
+
- Use this connection string, replacing the placeholder values for the database and password.</br>
(*Note: when pasting in the connection string, you will need to replace part of the connection string where it says '{your_password}' with your Azure SQL Server password*)
126
+
<details>
127
+
<summary>Azure SQL Server</summary>
128
+
- Browse to the SQL Database resource in the [Azure portal](https://ms.portal.azure.com/)</br>
129
+
- In the left blade click on the <b>Connection Strings</b> tab</br>
130
+
- Copy the <b>SQL Authentication</b> connection string</br>
131
+
</br>
132
+
(<i>Note: when pasting in the connection string, you will need to replace part of the connection string where it says '{your_password}' with your Azure SQL Server password</i>)
133
+
</details>
87
134
88
-
1. In'local.settings.json'in'Values', verify you have the below. If not, add the below and replace "Your Connection String" with the your connection string from the previous step:
135
+
1. Open the generated `local.settings.json` file and inthe `Values` section verify you have the below. If not, add the below and replace `{connection_string}` with the your connection string from the previous step:
@@ -113,47 +160,9 @@ These steps can be done in the Terminal/CLI or with PowerShell. Completing this
113
160
114
161
## Tutorials
115
162
116
-
### Create Azure SQL Database
117
-
118
-
We will create a simple Azure SQL Database. For additional reference on Azure SQL Databases, go [here](https://docs.microsoft.com/azure/azure-sql/database/single-database-create-quickstart?tabs=azure-portal).
119
-
120
-
- Create an Azure SQL Database
121
-
- Make sure you have an Azure subscription. If you don't already have an Azure Subscription, go [here](https://azure.microsoft.com/free/search/?&OCID=AID2100131_SEM_XzK4bAAAAJBpCjfl:20200918000154:s&msclkid=f33d47a9a4ec1c1b6ced18cd9bd2923f&ef_id=XzK4bAAAAJBpCjfl:20200918000154:s&dclid=CKLQqbL28esCFUrBfgod4BIBMA).
122
-
- Navigate to the [Azure portal](https://ms.portal.azure.com/)
123
-
- Click 'Create a resource', then search the marketplace for 'SQL Database' and select it. Provide a 'Subscription', 'Resource Group', and 'Database name.' Under the 'Server' field, click 'Create New'
124
-
<kbd></kbd>
125
-
- Fill in the fields of the 'New server' panel. Make sure you know your 'Server admin login' and 'Password' as you will need them later. Click 'OK' at the bottom of the panel.
126
-
- Click 'Review and Create' at the bottom of the page. Then press 'Create.' While you are waiting for your resource to be created, feel free to do the [Set Up Local .NET Function App](#Set-Up-Local-.NET-Function-App) step if you have not done so already and return here when completed.
127
-
- Once created, navigate to the SQL Database resource. In the left panel, click 'Query editor'
128
-
- Enter your Azure SQL login from when you created the SQL Database.
129
-
- If an error pops up for not being able to open the server, copy the Client IP address in the second sentence of the error message, and click 'set server firewall' at the bottom
130
-
- In the new window, click 'Add Client IP.' This will create an entry
131
-
- In the section with Rule Name, Start IP, and End IP, paste the IP address you just copied into the Start and End IP fields for the entry created in the previous step.
132
-
- Hit 'Save' in the top left and navigate back into the SQL Database login page.
133
-
- Enter your login. You should now be in the Query editor view
134
-
- Enter the below script and hit run to create a table. Once created, if you expand the Tables section by clicking the arrow, you should see a table
135
-
136
-
```sql
137
-
CREATE TABLE Employees (
138
-
EmployeeId int,
139
-
FirstName varchar(255),
140
-
LastName varchar(255),
141
-
Company varchar(255),
142
-
Team varchar(255)
143
-
);
144
-
```
145
-
146
-
- Enter the blow script and hit run to create an entry in the table. Once created, if you right click your table name and click 'Select Top 1000 Rows', you'll be able to see your entry present.
147
-
148
-
```sql
149
-
INSERT INTO [dbo].[Employees] values (1, 'Hello', 'World', 'Microsoft', 'Functions')
150
-
```
151
-
152
-
- Congratulations! You have successfully created an Azure SQL Database! Make sure you complete [Quick Start](#Quick-Start) before continuing to the rest of the tutorial.
153
-
154
163
### Input Binding Tutorial
155
164
156
-
Note: This tutorial requires that the Azure SQL database is setup as shown in [Create Azure SQL Database](#Create-Azure-SQL-Database).
165
+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](#Create-a-SQL-Server).
157
166
158
167
- Open your app that you created in'Set Up Your Local Environment'in VSCode
159
168
- Press 'F1' and search for'Azure Functions: Create Function'
@@ -201,7 +210,7 @@ Note: This tutorial requires that the Azure SQL database is setup as shown in [C
201
210
202
211
### Output Binding Tutorial
203
212
204
-
Note: This tutorial requires that the Azure SQL database is setup as shown in [Create Azure SQL Database](#Create-Azure-SQL-Database), and that you have the 'Employee.cs' class from the [Input Binding Tutorial](#Input-Binding-Tutorial).
213
+
Note: This tutorial requires that a SQL database is setup as shown in [Create a SQL Server](#Create-a-SQL-Server), and that you have the 'Employee.cs' class from the [Input Binding Tutorial](#Input-Binding-Tutorial).
205
214
206
215
- Open your app in VSCode
207
216
- Press 'F1' and search for 'Azure Functions: Create Function'
0 commit comments