← Back | Azure SQL Database — WebhookFlow Setup
Pre-Course · Database
Pre-Course · Database Setup

Azure SQL Database
for WebhookFlow

Connect the WebhookFlow microservice to Azure SQL Database — Microsoft's managed SQL Server in the cloud. Free tier available, runs from Windows, and tables are created automatically by Spring Boot JPA on first startup.

☁️ Azure SQL Database 🪟 Windows Machine ☕ Spring Boot + JPA 🗄️ SQL Server Engine
🧠
Concept
Why Azure SQL Database?
One database, zero local setup, cloud experience from day one
Analogy: H2 is a whiteboard — great for sketching, but wiped clean every restart. Azure SQL Database is a real filing cabinet in the cloud — data persists, it's shared, and it's exactly what production looks like.
OptionPersistenceSetupProduction-likeWe use
H2 in-memory Lost on restart Zero setup No Never
SQL Server on Windows Persists Heavy installer (1GB+) Yes No
Azure SQL Database ✓ Persists Azure portal (5 min) Yes — IS production Yes
Key insight: Azure SQL Database runs the exact same SQL Server engine as a local install. The JDBC driver is identical. The only difference is the hostname in the connection URL — localhost:1433 becomes yourserver.database.windows.net:1433. Spring Boot and JPA don't care.
Step 0
Prerequisites
What you need before starting
1

Azure Free Account

Go to azure.microsoft.com/free and sign up. You get $200 credit for 30 days and several services free for 12 months. Azure SQL Database (Basic tier, 2 GB) is free for 12 months.

2

Azure Data Studio — installed on Windows

Download from azure.microsoft.com/products/data-studio. It is the official SQL client for Windows — lighter than SSMS, optimised for Azure SQL. Free download, ~150 MB.

3

WebhookFlow project open in VS Code

You should already have the webhook project running with H2. We will swap the database without changing any Java code.

Note for the cohort: The instructor (Harish) creates one shared Azure SQL Server for the batch. Each student gets the server name and password via class. You do NOT need your own Azure account unless you want to experiment independently.
☁️
Step 1 — Instructor does this once
Create Azure SQL Server + Database
In the Azure portal — 5 minutes, free tier
1

Open Azure Portal → Create a resource

Go to portal.azure.com → click Create a resource → search for Azure SQL → select SQL Database.

2

Fill in the Basics tab

FieldValue
SubscriptionYour Azure subscription
Resource groupcampustoai-rg (create new)
Database namewebhookflow
ServerClick Create new → see step 3
Compute + storageClick Configure database → choose Basic (5 DTU, 2 GB, ~$5/month or free tier)
Backup redundancyLocally redundant
3

Create the SQL Server (logical server)

FieldValue
Server namewebhookflow-server (must be globally unique — add your initials if needed)
LocationSoutheast Asia or Central India (closest to students)
Authentication methodUse SQL authentication
Server admin loginsqladmin
PasswordWebhook@1234 (share with cohort — change before production)
4

Click Review + Create → Create

Deployment takes about 2–3 minutes. Once done, your server is at webhookflow-server.database.windows.net and the database is named webhookflow.

Spring Boot auto-creates tables: You do NOT need to run any CREATE TABLE SQL. When the app starts, JPA reads your @Entity classes and creates/updates all tables automatically (ddl-auto=update). The database just needs to exist.
🔥
Step 2
Configure Firewall Rules
Students connect from home — dynamic IPs, so open the firewall for the course duration
Home connections = dynamic IPs. Every home internet connection gets a different public IP from the ISP each session (DHCP). Adding individual student IPs doesn't work — they change. The right approach for an online course is to open the firewall to all IPs for the duration of the batch, then restrict it when the course ends.
1

Open Azure Portal → your SQL Server → Networking

Go to portal.azure.com → open webhookflow-server → left sidebar → NetworkingFirewall rules tab.

2

Add a rule that allows all IPs

Click Add a firewall rule and fill in:

FieldValue
Rule nameAllowCourseStudents
Start IP address0.0.0.0
End IP address255.255.255.255

Click Save. All students can now connect from any home IP without any further firewall changes.

3

After the batch ends — lock it down

Go back to Networking → delete the AllowCourseStudents rule → add only your own IP. This prevents any access once the course is over.

This is a teaching database, not a production database. Opening 0.0.0.0–255.255.255.255 is acceptable for a short course because: the database contains no real user data, the SA password is known only to the cohort, and Azure SQL still requires valid credentials — the firewall rule alone is not enough to get in. Remove the rule when the batch ends.
🖥️
Step 3
Connect with Azure Data Studio
Windows GUI tool — verify the database exists
1

Open Azure Data Studio → New Connection

Launch Azure Data Studio on Windows → click the plug icon (New Connection) in the top-left.

2

Enter connection details

FieldValue
Connection typeMicrosoft SQL Server
Serverwebhookflow-server.database.windows.net,1433
Authentication typeSQL Login
User namesqladmin
PasswordWebhook@1234
Databasewebhookflow
Encrypt connectionMandatory
Trust server certificateNo
3

Click Connect

You should see the webhookflow database in the sidebar. The database is empty for now — Spring Boot will create the tables when you first start the app.

4

After running the app — verify tables

Right-click webhookflowNew Query → run:

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';

You should see: webhook_event, webhook_subscription, delivery_log, event_source.

Step 4
Update Spring Boot
pom.xml + application.properties — 2 files, no Java changes
File: webhook/pom.xml

Remove the H2 dependency and add the SQL Server JDBC driver:

pom.xml — replace H2 with mssql-jdbc
<!-- REMOVE this H2 block completely --> <dependency> <groupId>com.h2database</groupId> <artifactId>h2</artifactId> <scope>runtime</scope> </dependency> <!-- ADD this instead --> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>mssql-jdbc</artifactId> <scope>runtime</scope> </dependency>
Spring Boot's BOM (Bill of Materials) manages the mssql-jdbc version automatically — no version number needed in the dependency.
File: webhook/src/main/resources/application.properties

Replace all H2 configuration with Azure SQL settings. Credentials come from environment variables (see Step 5).

application.properties — full contents
spring.application.name=webhook # ── Azure SQL Database ──────────────────────────────────────────────────────── # AZURE_SQL_SERVER → server name (without .database.windows.net) # AZURE_SQL_PASSWORD → admin password spring.datasource.url=jdbc:sqlserver://${AZURE_SQL_SERVER}.database.windows.net:1433;databaseName=webhookflow;encrypt=true;trustServerCertificate=false;hostNameInCertificate=*.database.windows.net;loginTimeout=30 spring.datasource.driver-class-name=com.microsoft.sqlserver.jdbc.SQLServerDriver spring.datasource.username=sqladmin spring.datasource.password=${AZURE_SQL_PASSWORD} # ── JPA / Hibernate ─────────────────────────────────────────────────────────── spring.jpa.hibernate.ddl-auto=update spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true spring.jpa.open-in-view=false # ── Server ──────────────────────────────────────────────────────────────────── server.port=8080
ddl-auto=update means JPA will CREATE all tables on first startup, and ADD columns if you add new fields to an entity later. It never drops existing data.
🔑
Step 5
Set Environment Variables on Windows
Two methods — PowerShell session or .env file for VS Code

Method A — PowerShell (current session only)

Open PowerShell and run these before mvn spring-boot:run:

PowerShell
$env:AZURE_SQL_SERVER = "webhookflow-server" $env:AZURE_SQL_PASSWORD = "Webhook@1234" # Then start the app in the same window: mvn spring-boot:run
Variables set this way last only for the current PowerShell window. You must set them again after closing.

Method B — .env file for VS Code (recommended)

Create a .env file in webhook/ (next to pom.xml). VS Code's launch.json reads it automatically when you press F5.

File: webhook/.env (create this file — never commit to git)
.env
AZURE_SQL_SERVER=webhookflow-server AZURE_SQL_PASSWORD=Webhook@1234
Add .env to .gitignore immediately. Never commit database passwords to git.
.gitignore — add this line
.env

Method C — Windows System Environment Variables (permanent)

Search Environment Variables in Start → Edit the system environment variablesEnvironment VariablesNew under User Variables:

AZURE_SQL_SERVER = webhookflow-serverServer name
AZURE_SQL_PASSWORD = Webhook@1234Admin password

After saving, restart VS Code or PowerShell for the new values to take effect.

Step 6
Verify Connection
Run the app — JPA creates all tables automatically
1

Set environment variables (if using Method A) then run

$env:AZURE_SQL_SERVER = "webhookflow-server" $env:AZURE_SQL_PASSWORD = "Webhook@1234" mvn spring-boot:run
2

Look for this in the startup log

HikariPool-1 - Start completed Hibernate: create table webhook_event ( Hibernate: create table webhook_subscription ( Hibernate: create table delivery_log ( Hibernate: create table event_source ( Started WebhookApplication in 4.2 seconds
3

Call the health endpoint

curl http://localhost:8080/health

Expected response: {"status":"UP","totalEvents":0}

4

Verify tables in Azure Data Studio

SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE';

Should show 4 tables: webhook_event, webhook_subscription, delivery_log, event_source.

Data persists: Stop the app, restart it — all tables and data remain in Azure SQL. This is the key difference from H2.
🔧
Reference
Troubleshooting
ErrorCauseFix
Could not connect to server Firewall rule missing or not saved Azure Portal → webhookflow-server → Networking → confirm the AllowCourseStudents rule exists with Start IP 0.0.0.0 and End IP 255.255.255.255, then Save
Login failed for user 'sqladmin' Wrong password, or SQL authentication disabled Check AZURE_SQL_PASSWORD env var; verify SQL auth is enabled in portal
Could not resolve placeholder 'AZURE_SQL_SERVER' Environment variable not set in this shell Run $env:AZURE_SQL_SERVER="webhookflow-server" first, then mvn spring-boot:run in the same PowerShell window
SSL connection required Missing encrypt=true in connection URL Ensure the JDBC URL in application.properties includes encrypt=true
Database 'webhookflow' does not exist Database not created in portal Go to Azure portal → SQL Databases → verify webhookflow database exists on your server
Tables not created after startup ddl-auto not set to update Check application.properties has spring.jpa.hibernate.ddl-auto=update
Azure Data Studio: certificate error Trust server certificate off In Azure Data Studio connection, set Encrypt connection to Mandatory and Trust server certificate to No. Azure SQL uses a valid CA cert.

Moving to production (Phase 2+)

You are already on Azure SQL — there is nothing to migrate. For production, create a separate Azure SQL Database (Standard tier, more DTUs) and update the AZURE_SQL_SERVER environment variable to the new server name. Zero Java code changes required.