# Azure Synapse Analytics Destination

Azure's [Azure Synapse Analytics](https://azure.microsoft.com/en-us/services/synapse-analytics/), previously known as Azure SQL Data Warehouse, is a limitless analytics service that brings together enterprise data warehousing and Big Data analytics.

> \[!NOTE]
>
> Delivery Overview, Segment's built-in observability tool, is now in public beta for storage destinations. For more information, see the [Delivery Overview](/docs/segment/connections/delivery-overview/) documentation.

## Getting started

Complete the following prerequisites in Microsoft Azure before connecting your Azure Synapse Analytics databases to Segment:

1. Sign up for an [Azure subscription](https://azure.microsoft.com/en-us/free/).
2. Provision a [Dedicated SQL Pool](https://docs.microsoft.com/en-us/azure/sql-data-warehouse/create-data-warehouse-portal).

## Connect your Azure database to Segment

To connect your Azure database to Segment, [give Segment access to your SQL Data Warehouse](#give-segment-access-to-your-sql-data-warehouse) and [configure an Azure Synapse Analytics destination](#configure-an-azure-synapse-analytics-destination-in-segment).

### Give Segment access to your SQL Data Warehouse

1. Create a server login for Segment to use. This can be accomplished by running the following SQL command on your SQL Server's `master` database:

```sql
CREATE LOGIN Segment WITH PASSWORD = '<strong password>';
```

2. Connect to your Azure database.
3. Segment uses Azure Blob Storage to hold data that is being loaded into Azure Synapse Analytics. In order to facilitate this, a `MASTER KEY` is needed in order for credentials that Segment saves to the database to be encrypted. To create a master key, run the following command:

```sql
CREATE MASTER KEY;
```

If you are using your Azure Synapse Analytics instance for more than just a Segment integration, it is possible you already have a master key. Running the command more than once will not create a new master key.

4. Create a new database user using the server login that you created in a previous step:

```sql
CREATE USER Segment FOR LOGIN Segment;
```

5. Run the following command to give your new user the permissions to load data and manage the resources in your database:

```sql
GRANT CONTROL TO Segment;
```

6. Assign this new user a [resource allocation class](https://docs.microsoft.com/en-us/azure/sql-data-warehouse/resource-classes-for-workload-management):

```sql
EXEC sp_addrolemember 'largerc', 'Segment';
```

The default resource allocation class (`smallrc`) may not give Segment enough memory to perform bulk loads, so Segment recommends starting with `largerc`. The larger Dynamic Resource Classes give more memory and allow fewer concurrent queries, which is a better fit for Segment's loading strategy.

7. By default, you cannot connect to Azure Synapse Analytics from the public internet. In order for Segment to connect to your instances, create a [server-level firewall rule](https://docs.microsoft.com/en-us/azure/sql-data-warehouse/create-data-warehouse-portal#create-a-server-level-firewall-rule) that allows connections from the [Segment IPs](/docs/segment/connections/storage/warehouses/faq/#which-ips-should-i-allowlist):

```sql
EXEC sp_set_firewall_rule N'<rule name>', '52.25.130.38', '52.25.130.38'; 
```

### Connect Azure to Segment

> \[!NOTE]
>
> With unified warehouse credientials you can create warehouse credentials and use them across Segment warehouse products. Segment is actively working on this feature. Some functionality may change before it becomes generally available.

To connect Azure to Segment:

1. Navigate to your product area in the Segment app.
   * For storage destinations, navigate to **Connections > Destinations** and select the **Storage** tab. Click **+ Add storage destination**.
   * For Profiles Sync, navigate to **Unify > Profiles Sync**.
2. Select *Azure* as your warehouse.
3. Select an existing warehouse credential or create a new warehouse credential by completing the following fields for your Azure instance.
   * **Server**: Your Azure dedicated SQL pool server.
   * **Port**: The port used for connecting to your Azure dedicated SQL pool. The default port for Azure dedicated SQL pool is 1433, but your port may be different.
   * **Database name**: The name of your Azure dedicated SQL pool that Segment uses in order to sync data.
   * **Username**: The Azure user that Segment uses to run SQL in your warehouse.
   * **Password**: The password of the user above.
4. Test your connection.
5. Click **Save**.

## Best Practices

### Making sure Segment has enough resources to load your data

The default [resource allocation class](https://docs.microsoft.com/en-us/azure/sql-data-warehouse/resource-classes-for-workload-management) (`smallrc`) may not give Segment enough memory to perform bulk loads, so Segment recommends using a larger class (`largerc`). Larger classes allocate more memory and limit the number of concurrent queries, which is a better fit for Segment's loading strategy.

### Using Selective Sync

Users with a Business Tier plan can enable Selective Sync for their Azure Synapse Analytics destination. With Selective Sync, you can customize which collections and properties from a source are sent to each warehouse, which leads to faster, more relevant syncs. To learn more about Selective Sync, review the [Warehouse Syncs](/docs/segment/connections/storage/warehouses/warehouse-syncs/#warehouse-selective-sync) documentation.

### Allowlisting IPs

Segment recommends enabling IP allowlists for added security. All Segment users with workspaces hosted in the US who use allowlists in their warehouses must update those allowlists to include the following ranges:

* `52.25.130.38/32`
* `34.223.203.0/28`

Users with workspaces in the EU must allowlist `3.251.148.96/29`.

## Troubleshooting

### Segment is not able to connect to Azure Synapse Analytics

If you encounter this error, create a [server-level firewall rule](https://docs.microsoft.com/en-us/azure/sql-data-warehouse/create-data-warehouse-portal#create-a-server-level-firewall-rule) that allows connections from the [Segment IPs](/docs/segment/connections/storage/warehouses/faq/#which-ips-should-i-allowlist).

### Incorrect server name - no such host

When setting up Azure warehouse, you might run into this error:

```text
An unexpected error occurred
failed to connect to Azure SQL: lookup xxx.database.windows.net.database.windows.net: no such host
```

If you encounter this error, it is possible that you have included `.database.windows.net` in your server name. For the Server Name field, you only need to enter the part of the server name prior to `.database.windows.net`.
