> For the complete documentation index, see [llms.txt](https://docs.smaq.io/documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.smaq.io/documentation/connections/sql-databases/microsoft-azure-sql.md).

# Microsoft Azure SQL

Connect a Microsoft Azure SQL Database (managed SQL Server) to SMAQ.

### Step 1 — Collect connection details

In the Azure Portal:

1. **SQL databases → click your database**.
2. From **Overview**, copy the **Server name** (e.g. `acme-prod.database.windows.net`).
3. Note the **Database name**.
4. Default port is **1433**.

> **\[Screenshot needed]** Azure SQL Database Overview pane with Server name and Database name highlighted.

### Step 2 — Allow SMAQ's IPs in the firewall

1. **SQL Server → Networking** (the server resource, not the database).
2. Toggle **Public access** to Selected networks (if not already).
3. **Firewall rules → Add a rule** for each SMAQ outbound IP. Get the IPs from **<info@smaq.io>**.
4. Save.

> **\[Screenshot needed]** Firewall rules pane with SMAQ IPs listed.

### Step 3 — Create a read-only user

Connect to your DB as admin (via Azure Data Studio, SSMS, or `sqlcmd`):

```sql
CREATE LOGIN smaq_readonly WITH PASSWORD = 'long-random-string';
USE your_db;
CREATE USER smaq_readonly FOR LOGIN smaq_readonly;
EXEC sp_addrolemember 'db_datareader', 'smaq_readonly';
```

### Step 4 — Add the connection in SMAQ

1. SMAQ project → **Data Source → Add data source**.
2. Pick **Microsoft Azure SQL**.
3. Fill in:
   * **Host**: the server name (`acme-prod.database.windows.net`)
   * **Port**: 1433
   * **Database**, **Username** (`smaq_readonly`), **Password**
   * **SSL mode**: Require (Azure SQL always uses encrypted connections)
4. **Test connection** → **Connect**.

### Troubleshooting

* **"Cannot open server requested by the login"** — Azure firewall isn't allowing SMAQ. Double-check the IP rules and that you edited the rules on the server, not the database.
* **"Login failed for user"** — the user was created at the database level but the login wasn't created at the server level. Re-run `CREATE LOGIN ...`.
* **Slow queries** — Azure SQL has a service tier that limits DTU/vCore. Cheap tiers throttle aggressively under analytical workloads.

### Active Directory authentication

SMAQ doesn't currently support Azure AD-based authentication for Azure SQL. Use SQL authentication (username/password) instead. Talk to <info@smaq.io> if AAD auth is a hard requirement.
