> ## Documentation Index
> Fetch the complete documentation index at: https://docs.asteragents.com/llms.txt
> Use this file to discover all available pages before exploring further.

# SQL Server

> Connect Microsoft SQL Server or Azure SQL Database to your Agent

## Overview

The SQL Server integration enables your agents to execute T-SQL queries against Microsoft SQL Server and Azure SQL Database. Ideal for querying operational data, generating reports, and analyzing business metrics stored in SQL Server.

## Features

* **Full T-SQL Support**: Execute any T-SQL query including SELECT, INSERT, UPDATE, DELETE, and DDL operations
* **Azure SQL Compatible**: Works with both on-premises SQL Server and Azure SQL Database
* **Structured Results**: Returns data with column headers and type information
* **CSV Export**: Automatically generates downloadable CSV files for large result sets
* **Smart Truncation**: Token-based result truncation to manage response sizes while preserving full CSV output

## Prerequisites

* SQL Server instance or Azure SQL Database accessible over the network
* Database user credentials with appropriate permissions
* Network connectivity from Vercel to your SQL Server (may require firewall rules)

## Setup Guide

<Steps>
  <Step title="Prepare Database Access">
    Create a dedicated database user for agent access. For read-only use cases:

    ```sql theme={null}
    CREATE LOGIN aster_agent WITH PASSWORD = 'your_password';
    CREATE USER aster_agent FOR LOGIN aster_agent;
    GRANT SELECT ON SCHEMA::dbo TO aster_agent;
    ```
  </Step>

  <Step title="Configure Network Access">
    Aster's database tools connect from two **static egress IPs**:

    ```
    52.7.142.31
    44.199.142.97
    ```

    Allowlist **both** so your server accepts connections from Aster:

    * **Azure SQL**: add both IPs as firewall rules on the SQL server (Networking → Firewall rules)
    * **On-premises**: allow inbound connections from both IPs on port 1433
  </Step>

  <Step title="Enable SQL Server Integration">
    In Aster Agents, navigate to **Control Hub > Integrations** and locate the SQL Server card. Click **Connect** and provide:

    * **Server Host** — hostname or IP (e.g., `myserver.database.windows.net` for Azure)
    * **Port** — default is 1433
    * **Database Name** — the database to connect to
    * **Username** — database user credentials
    * **Password** — database user password
    * **Encrypt Connection** — enable for Azure SQL (required) and recommended for all connections
  </Step>

  <Step title="Add Tool to Your Agent">
    Edit your agent and enable the **SQL Server** tool. The agent will be able to execute T-SQL queries against your configured database.
  </Step>
</Steps>

## Security Considerations

* **Use a dedicated read-only account** unless write access is specifically needed
* **Apply least-privilege permissions** — grant access only to the schemas and tables the agent needs
* **Enable TLS encryption** for all connections (required for Azure SQL)
* **Use Azure AD authentication** where possible for Azure SQL Database
* **Monitor query activity** in SQL Server Audit or Azure SQL auditing
* **Set connection and request timeouts** — the integration uses 15-second connection and 30-second request timeouts by default

## Troubleshooting

<AccordionGroup>
  <Accordion title="Connection Timeout">
    * Verify the server hostname and port are correct
    * Check firewall rules — your SQL Server must accept connections from Aster's static egress IPs (`52.7.142.31` and `44.199.142.97`)
    * For Azure SQL, ensure "Allow Azure services and resources to access this server" is enabled if needed
    * Confirm the SQL Server instance is running and accepting TCP/IP connections
  </Accordion>

  <Accordion title="Authentication Failed">
    * Verify username and password are correct
    * For Azure SQL, use the full username format: `username@servername`
    * Check that SQL Server authentication mode is enabled (not just Windows Authentication)
    * Confirm the user account is not locked or disabled
  </Accordion>

  <Accordion title="Encrypt Connection Issues">
    * Azure SQL requires encryption — set Encrypt Connection to "Enabled"
    * For on-premises servers without a trusted certificate, you may need to disable encryption (not recommended for production)
    * If using a self-signed certificate, the integration will trust it when encryption is disabled
  </Accordion>

  <Accordion title="Query Timeout">
    * The default request timeout is 30 seconds — optimize long-running queries with indexes or filtering
    * Break large queries into smaller, more targeted queries
    * Use `TOP` or pagination to limit result set sizes
  </Accordion>
</AccordionGroup>

## Related Tools

* **SQL Server** (`mssql_sql`) - Execute T-SQL queries
