> Source: https://help.wastenot.io/connectors/mssql

# Microsoft SQL Server

Connect a Microsoft SQL Server database to WasteNot to pull customer and transaction data directly from your database. Write custom SQL queries to define exactly what data feeds into your audiences.

## Prerequisites

* A SQL Server database accessible over the internet (SQL Server 2016 or later, or Azure SQL)
* A database user with read-only access to the tables you want to query
* The database host, port, name, and credentials

> **Note:**
>
> Your database must be reachable from the internet. SSH tunneling is not
> currently supported. If your database is behind a firewall, you will need to
> allowlist WasteNot's IP addresses — contact
> <support@wastenot.io> for the current list.

## Adding the SQL Server data source

1. [Add a new SQL Server data source](https://app.wastenot.io/integrations/connectors/new/mssql)
   in WasteNot
2. Enter a **Name**
3. Enter your connection details:
   * **Host** — The hostname or IP address of your SQL Server instance
   * **Port** — The port SQL Server is listening on (default: `1433`)
   * **Database** — The name of the database to connect to
   * **Username** — A read-only database user
   * **Password** — The password for the database user

> **Note:**
>
> We strongly recommend creating a dedicated read-only user for WasteNot rather
> than using an admin account. This limits access to only the data you want to
> sync.

4. Click **Connect**

WasteNot will create the data source using the connection details you entered. After that, you can open the data source page to manage custom streams.

## Custom streams

Once connected, you can create streams to define what data WasteNot pulls from your database. Each stream is a SQL query that returns rows matching WasteNot's expected format.

See the [Writing Custom Queries](https://help.wastenot.io/guides/custom-queries) guide for full details on required columns and event types.

1. Go to your SQL Server data source detail page
2. Click **New Stream**
3. Give the stream a name, select an event type, and enter your SQL query
4. Check **Enabled** and click **Save**

WasteNot will run enabled streams on a schedule and sync the results automatically.

## Frequently asked questions

### What permissions does the database user need?

The user needs `SELECT` privileges on the tables or views referenced in your stream queries. You can also grant access to specific schemas to limit what WasteNot can see.

### Does this work with Azure SQL?

Yes. Azure SQL Database is fully supported. Use your Azure SQL server hostname (e.g., `yourserver.database.windows.net`) as the host.

### My data source shows "Failed" status

Common causes:

* The database is not reachable from the internet
* Credentials are incorrect or the user has been disabled
* A firewall is blocking the connection (check Azure firewall rules if using Azure SQL)
* SQL Server is not configured to accept TCP/IP connections

Check with your data team, or reach out to <support@wastenot.io> for help.
