Release Status Released Availability Free
Supported Versions n/a SSL Connections Supported
Whitelist Tables/Columns Supported/Supported View Replication Supported
Destination Incompatibilities None

Connecting MSSQL

In this article, we’ll walk you through connecting your Microsoft SQL Server (MSSQL) database to Stitch. You’ll need some tech expertise to complete the setup, so we recommend looping in a developer or a member of your tech team to help out if you haven’t done this before.

Connecting an MSSQL database is a five-step process:

  1. Whitelist the Stitch IP addresses
  2. Create a database user for Stitch
  3. Enter the connection info into Stitch
  4. Define the Replication Frequency
  5. Sync data & select Replication Methods

Prerequisites

Connecting a MSSQL database to Stitch requires that your server allows:

  • Connections over TCP/IP
  • Mixed mode authentication

Make sure your server is set up properly before continuing. If you need some help figuring out your hosting details, ping the developer helping you or feel free to get in touch with us.

Whitelist Stitch’s IP Addresses

For the connection to be successful, you’ll need to configure your firewall to allow access from our IP addresses. Whitelist the following IPs before continuing onto the next step:

  • 52.23.137.21/32

  • 52.204.223.208/32

  • 52.204.228.32/32

  • 52.204.230.227/32

Create a Stitch Database User

To bring your MSSQL data into Stitch, the system will run SELECT queries on your database. Initially this is done to get a snapshot of the database’s structure. After your first update cycle is complete, you can set Replication Methods for individual tables to potentially reduce your update times and the load on your server.

Creating a user with SELECT privileges can either be done via a query or the MSSQL UI. In this section, we’ll walk you through using the query method.

After logging in to your database, the first step is to create a SQL login for the database user. You can accomplish this by running the following query:

CREATE LOGIN [stitch_username] WITH PASSWORD=’[password]’
go

Next, you need to grant the user access to the database:

USE [database]
go

After you’ve successfully granted access, you need to create the database user and map them to the database:

CREATE USER [stitch_username] FOR LOGIN 
go

The last step is to grant the user SELECT privileges. Running the following query will give the user SELECT privileges to all tables in the database:

GRANT SELECT to [stitch_username]
go

If you don’t want to limit the Stitch user to specific tables, you can move onto the next section. If you do, however, you can use this query:

GRANT SELECT ON [schema name].[table name] TO [stitch_username]
go

The next step is to enter the credentials into Stitch and test the integration.

Enter the Connection Info into Stitch

To wrap things up, you need to enter the database connection and user info into Stitch.

  1. On the Stitch Dashboard page, click the Add an Integration button.

  2. Click the MSSQL icon.
  3. Enter a name for the integration. This is the name that will display on the for the integration; it’ll also be used to create the schema in your data warehouse.

    For example, the name “Stitch MSSQL” would create a schema called stitch_mssql in the data warehouse. This schema is where all the tables for this integration will be stored.

  4. Fill in the connection info for the database:
    • Host: In general, this will be 127.0.0.1 (localhost), but could also be some other network address (ex: 192.68.0.1) or your server’s public IP address. Note that this must be the actual address - entering localhost into this field will cause connection issues.
    • Port: Enter the MSSQL port on your server. (1433 by default)
    • Username: Enter the Stitch MSSQL user’s username.
    • Password: Enter the password for the Stitch MSSQL user.
    • Database: Enter the name of the default database Stitch will connect to. Don’t worry: we’ll find all the databases you gave the Stitch user access to, but we need an initial database to complete the connection.

In addition, click the Connect using SSL checkbox if you’re using an SSL connection.

Define the Replication Frequency

The Replication Frequency controls how often Stitch will attempt to replicate data from your MSSQL integration. By default the frequency is set to 30 minutes, but you can change it to better suit your needs.

Before setting the Replication Frequency, note that:

  • The more often MSSQL is set to replicate, the higher the number of replicated rows.
  • The number of rows in the source may not equal the number of rows replicated by Stitch. Tables that use Full Table Replication will result in a higher number of replicated rows.

  • If you’re using a data warehouses that doesn’t natively support nested structures, you’ll see a higher number of replicated rows due to the de-nesting Stitch performs.

To help prevent overages, we recommend setting the Replication Frequency to something less frequent - like 6 hours instead of 30 minutes. For tips on reducing your row count, check out the Reducing Your Row Count section of our Billing Guide.

After selecting a Replication Frequency, click Save Integration.

Select Tables & Columns to Sync

The last step is to select the tables and columns you want to sync. When you sync a table, you’ll also need to define its Replication Method and, if using Incremental Replication, its Replication Key.

You can sync tables and columns by:

  1. In the Integration Details page, click the Tables to Replicate tab.
  2. Locate a table you want to replicate.
  3. Click the checkbox next to the object’s name. A green checkmark means the object is set to sync.
  4. If there are child objects, they’ll automatically display and you’ll be prompted to select some.
  5. After you set a table to sync, the Table Settings page will display.
  6. In the Table Settings page, you’ll need to define the table’s Replication Method and, if using Incremental Replication, its Replication Key.
  7. Repeat this process for every table you want to replicate. Note that when you sync a table, by default all columns will also be set to sync.

MSSQL’s Intial Sync

After you finish setting up MSSQL, you might see its Sync Status show as Pending on either the Stitch Dashboard or in the Integration Details page.

For a new integration, a Pending status indicates that Stitch is in the process of scheduling the initial sync for the integration. This may take some time to complete.


Replicating Data from MSSQL

When you connect a database as an input, Stitch only needs read-only access to the databases, tables, and columns you want to sync. There are two processes Stitch runs during the Extraction phase of the replication process: a structure sync and a data sync.

Structure Sync

The first part of the replication process is called a structure sync. This process will detect any changes to the structure of your database. For example: a new column is added to one of the tables you’re syncing in Stitch.

To perform a structure sync, Stitch runs queries on the databases and partitions tables in the sys schema.

Data Sync

The second step in the Extraction phase is called a data sync. This is where Stitch actually pulls data out of your database for replication. The method Stitch uses is the same for all databases, but differs depending on the Replication Method that each table uses.

Full Table Replication

For tables using Full Table Replication, Stitch runs a single query (shown below) and reads out of the resulting cursor in batches.

select column_a, column_b <,...> from table_a

Incremental Replication

For tables using Incremental Replication, Stitch runs a single query (shown below) and reads out of the associated cursor in batches.

select column_a, column_b <,...> from table_a
where replication_key_column >=last_bookmark_value
order by replication_key_column

Recommendations

While we make every effort to ensure the queries that Stitch runs don’t impart significant load on your databases, we still have some recommendations for guaranteeing database performance:

  • Use a replica database instead of connecting directly. We recommend using read replicas in lieu of directly connecting production databases with high availability and performance requirements.
  • Apply indexes to Replication Key columns. We restrict and order our replication queries by this column, so applying an index to the columns you’re using as Replication Keys can improve performance.


Questions? Feedback?

Did this article help? If you have questions or feedback, please reach out to us.