---
title: "SQL Server - Documentation"
description: "Connect Microsoft SQL Server, Azure SQL, or Amazon RDS SQL Server with Windows or SQL authentication."
canonical: "https://www.aifordatabase.com/docs/sql-server/"
---

# SQL Server

intermediate 5 min read

## Connecting SQL Server

AI for Database supports Microsoft SQL Server 2017+, Azure SQL Database, and Amazon RDS for SQL Server.

### Create a Read-Only User

```sql
-- Create a login
CREATE LOGIN aifordb_reader WITH PASSWORD = 'a-strong-random-password';

-- Switch to your database
USE your_database;

-- Create a user mapped to the login
CREATE USER aifordb_reader FOR LOGIN aifordb_reader;

-- Grant read access
ALTER ROLE db_datareader ADD MEMBER aifordb_reader;
```

The `db_datareader` role grants SELECT access on all tables and views in the database.

### Connection Settings

| Field | Example |
| --- | --- |
| Host | `sqlserver.example.com` |
| Port | `1433` |
| Database | `production` |
| Username | `aifordb_reader` |
| Password | `(your password)` |
| Encrypt | `true` |

### Azure SQL

For Azure SQL Database, use the full server name (e.g., `yourserver.database.windows.net`). Ensure the AI for Database IP is added to the Azure SQL firewall rules under **Networking**.

Azure Active Directory authentication is supported on Enterprise plans. Contact support for setup instructions.

### Windows Authentication

For on-premise SQL Server instances using Windows Authentication, you will need to use the self-hosted version of AI for Database and configure the service to run under a Windows account that has read access to the database.

### Troubleshooting

**Cannot open server requested by the login**: Ensure the user is mapped to the correct database. Run `SELECT name FROM sys.database_principals WHERE name = 'aifordb_reader';` to check.

**Encryption not supported**: Set the Encrypt field to `false` if your SQL Server does not have TLS configured. We recommend enabling TLS for production.

Source: https://www.aifordatabase.com/docs/sql-server/
