SQL Writer
This guide shows you how to work with Azure SQL Database locally using Azure Functions and SQLAlchemy. This lab demonstrates how to process HTTP POST requests and persist data into a local SQL database.
Prerequisites
Section titled “Prerequisites”- Docker installed and running.
- Dev Containers extension installed (optional).
How to execute
Section titled “How to execute”-
Setup Environment:
Open VS Code in the project folder and execute this command in the Command Palette:
Terminal window > Dev Containers: Reopen in Container- Run the setup script to install tools and dependencies:
Terminal window scripts/setup-mve.sh - Start Infrastructure: Launch the SQL Edge and Azurite containers:
Terminal window docker compose up -d
- Run the setup script to install tools and dependencies:
-
Start Azurite: From the Command Palette, select Azurite: Start Blob Service. This starts the local blob storage emulator required by the Azure Functions runtime.
-
Start Function Host:
Terminal window func start -
Run the Example:
Terminal window python main.py
Validate results
Section titled “Validate results”This lab includes a pre-configured connection profile for the SQL Server (mssql) extension in .vscode/settings.json.
- Open the SQL Server extension in VS Code.
- Select the
Azure SQL Edge (Local)connection profile. - Run the following query to verify the data:
SELECT * FROM Users;
Connect using the connection details defined in .vscode/settings.json:
- Server
localhost. - Port
1433. - Database
UserDB.
Clean Up
Section titled “Clean Up”docker compose down -vTroubleshooting
Section titled “Troubleshooting”| Issue | Solution |
|---|---|
ImportError: libodbc.so.2 | Run scripts/setup-mve.sh to install ODBC system dependencies. |
AzureWebJobsStorage error | Ensure Azurite Blob Service is started (Azurite: Start Blob Service) and port 10000 is available. |