Generic SQL Server Setup Guide
Follow these instructions to replicate your generic SQL Server database to your destination using Fivetran.
Prerequisites
To connect your generic SQL Server database to Fivetran, you need:
- SQL Server 2012 - 2022
- Your database host's IP (e.g.,
1.2.3.4
) or domain (your.server.com
) - Your database's port (usually
1433
)
IMPORTANT: We do not support single-user mode.
If you want to use Binary Log Reader as your incremental sync method, you also need:
- SQL Server 2019-2022 on Windows with .NET Framework 4.8 installed
- A SQL Server database with a system administrator account
- A SQL Server admin account on the database's host machine
- Access to your database's host machine
- Ability to install CLR stored procedures
- Source database must be in full recovery mode and have a full database backup
NOTE: The database must be in a state that a point-in-time recovery can be made.
Setup instructions
IMPORTANT: Do not perform the Choose connection method step if you want to use Hybrid Deployment for your data pipeline.
Choose connection method
First, decide whether to connect your generic SQL Server database directly, using an SSH tunnel, using AWS PrivateLink, using Azure PrivateLink, or using Proxy Agent.
Connect directly (TLS required)
IMPORTANT: You must have TLS enabled on your database to connect directly to Fivetran. Follow Microsoft's TLS setup instructions to enable TLS on your database.
Fivetran connects directly to your database instance. This is an easy and secure connection method.
To connect directly, configure your firewall and/or other access control systems to allow incoming connections to your SQL Server host and port (usually 1433
) from Fivetran's IPs for your database's region. How you do this will vary based on how your SQL Server database is hosted (cloud platform, on-premises, etc.)
When connecting to a named instance, provide your SQL Server host and instance name as the Host value (in the format <host>\<instance_name>
) in your connection setup form. If the SQL Server Browser service is active on your database, you can use port 1433
as the Port value if you want Fivetran to dynamically retrieve the port number of your named instance using this service. Otherwise, use the named instance port as the Port value.
Connect using SSH (TLS optional)
Fivetran connects to a separate server in your network that provides an SSH tunnel to your database. You must connect through SSH if your database is in an inaccessible subnet.
To connect using SSH, do the following:
In your connection setup form, select Connect via an SSH tunnel to expose Fivetran's public SSH key. Copy the key by clicking the blue clipboard icon.
Add the public key to the
authorized_keys
file of your SSH server. The key must be all on one line, so make sure that you don't introduce any line breaks when cutting and pasting.If you want Fivetran to tunnel SSH over TLS, follow Microsoft's TLS setup instructions to enable TLS on your database. Even though TLS is optional, TLS 1.0 is never supported. This is because the server will attempt to encrypt the authentication traffic with an obsolete TLS version, and Fivetran will refuse any TLS 1.0 connection, as it has been deprecated by the IETF.
WARNING: You can only connect to named instances through an SSH tunnel if you specify your SQL Server host as the Host value and the named instance port as the Port value in your connection setup form.
Connect using AWS PrivateLink
IMPORTANT: You must have a Business Critical plan to use AWS PrivateLink.
AWS PrivateLink allows VPCs and AWS-hosted or on-premises services to communicate with one another without exposing traffic to the public internet. PrivateLink is the most secure connection method. Learn more in AWS’ PrivateLink documentation.
Follow our AWS PrivateLink setup guide to configure PrivateLink for your database.
Connect using Azure Private Link
IMPORTANT: You must have a Business Critical plan to use Azure Private Link.
Azure Private Link allows Virtual Networks (VNets) and Azure-hosted or on-premises services to communicate with one another without exposing traffic to the public internet. Learn more in Microsoft's Azure Private Link documentation.
Follow our Azure PrivateLink setup guide to configure Private Link for your database.
Connect using Proxy Agent
Fivetran connects to your database through the Proxy Agent, providing secure communication between Fivetran processes and your database host. The Proxy Agent is installed in your network and creates an outbound network connection to the Fivetran-managed SaaS.
To learn more about the Proxy Agent, how to install it, and how to configure it, see our Proxy Agent documentation.
TLS Versions - Additional Information
For some connection methods listed in the previous section, TLS is either required or optional.
IMPORTANT: TLS 1.0 is never permitted by Fivetran. Both direct connections and SSH connections will fail with TLS 1.0 enabled.
Steps to check TLS version
If you're unsure of your TLS version, you can check it in the following way:
- Navigate to the
run
menu. - Run
regedit
. - Check the following registry values:
- for TLS 1.1:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client\DisabledByDefault
must be set to 0HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.1\Client\Enabled
must be set to 1
- for TLS 1.2:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client\DisabledByDefault
must be set to 0HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2\Client\Enabled
must be set to 1
- for TLS 1.1:
Allow TCP/IP protocol
Verify that your database server is configured to allow TCP/IP connections. If your database instance does not have TCP/IP protocol enabled, follow the instructions below.
Enable TCP/IP protocol
Open SQL Server Configuration Manager.
In the tree pane, click SQL Server Network Configuration to expand it.
Click Protocols for YourInstanceName. If you specified the default instance during installation, the instance name will be MSSQLSERVER.
In the Status column, verify that TCP/IP is Enabled.
TIP: If Disabled appears, right-click TCP/IP, then click Enable.
Right-click TCP/IP, then select Properties.
Go to the IP Addresses tab and scroll all the way down.
In the IPAll section, enter your database's port number (usually
1433
) for the TCP Port, then click Apply.Click OK in the warning dialog box that pops up.
Click OK in the TCP/IP Properties dialog box.
In the tree pane, click SQL Native Client Configuration to expand it, then click Client Protocols.
In the right-hand column, verify that Enabled appears next to TCP/IP.
TIP: If Disabled appears, right-click TCP/IP, then click Enable.
Right-click TCP/IP, then select Properties.
Verify that the Default Port is
1433
and that Yes appears next to Enabled.Click OK to exit the TCP/IP Properties dialog box.
In the tree pane, click SQL Server Services.
In the right pane, right-click SQL Server (YourInstanceName), then click Restart.
Choose incremental sync method
To keep your data up to date after the initial sync, we use one of the following incremental sync methods. These mechanisms let Fivetran copy only the rows that have changed since the last data sync so we don't have to copy the whole table every time. Learn more in our Updating data documentation.
Choose to enable change tracking, change data capture, Binary Log Reader, or Fivetran Teleport Sync. Depending on whether you are connecting Fivetran to your primary database or a replica, you may be limited in the method you can choose. See our CT vs CDC vs Binary Log Reader vs Fivetran Teleport Sync chart for more information.
NOTE: You will configure your incremental sync method in later steps.
Change tracking
Change tracking (CT) records when a row in a table has changed, but does not capture the data that was changed. CT also does not capture how many times the row changed or record any previous changes. CT is a built-in tracking mechanism of SQL Server.
IMPORTANT: You cannot use CT if you are connecting Fivetran to a replica.
To learn more, see our change tracking documentation.
Change data capture
Change data capture (CDC) tracks every change that is applied to a table and records those changes in a shadow history table, so you can see how many times a row has changed and view past changes. CDC is a built-in tracking mechanism of SQL Server.
Learn more in our CDC documentation.
Fivetran Teleport Sync
Fivetran Teleport Sync is a proprietary incremental sync method that can add delete capture with no additional setup other than a read-only SQL connection.
Learn more in our Fivetran Teleport Sync documentation.
Binary Log ReaderPrivate Preview
Binary Log Reader is a proprietary incremental sync method that uses a dynamic link library (DLL) to read files directly in your SQL Server host machine's file system. It captures what data was changed and when, so you can see how many times a row has changed and view past changes.
Learn more in our Binary Log Reader documentation.
Create user
Create a database user for Fivetran's exclusive use. The Fivetran user must be a SQL database user, not an Active Directory user.
Connect to your SQL Server database as an Admin user.
Execute the following command to create a Fivetran user with database password authentication. Replace
<database>
with the name of your database and<username>
and<password>
with a username and password of your choice:USE [<database>]; CREATE LOGIN <username> WITH PASSWORD = '<password>'; CREATE USER <username> FOR LOGIN <username>;
Grant user permissions
Grant Fivetran database user the permissions required to capture changes from the SQL Server database. Follow the instructions for your chosen incremental sync method.
CT, CDC, or Fivetran Teleport Sync
Grant the Fivetran user SELECT permission for the databases, schemas, tables, or specific columns you want Fivetran to sync.
You can grant access to everything in a given database:
GRANT SELECT on DATABASE::<database> to <username>;
or all tables in a given schema:
GRANT SELECT on SCHEMA::<schema> to <username>;
or a specific table:
GRANT SELECT ON [<schema>].[<table>] TO <username>;
or a set of specific columns in a table:
GRANT SELECT ON [<schema>].[<table>] ([<column 1>], [<column 2>], ...) TO <username>;
(Optional) For SQL Server for Linux, if you are using Change Tracking with history mode enabled, to improve performance and reduce delays, you may want to grant the necessary permissions to the Fivetran user by running the following command:
USE [master]; GRANT VIEW SERVER STATE TO <username>;
This grants the Fivetran user access to server state information, minimizing the dependency on checkpoint timing and reducing update delays. See the Sync Delays with SQL Server for Linux Using Change Tracking with History Mode Enabled troubleshooting page for details.
Binary Log Reader Private Preview
Configure the permissions model that best fits your specific business needs:
- SysAdmin model: This model is the easiest to configure. It offers broad permissions and authority over the entire SQL Server instance. A SysAdmin has unrestricted permissions, including the ability to modify server settings, manage databases, and write to any table.
- Minimal model: This model requires the least permissions. It does not require
sysadmin
ordb_owner
rights. Instead, the Fivetran database user performs specific actions by using wrapper stored procedures. These procedures encapsulate only the necessary functionality from higher-privileged roles, ensuring Fivetran can execute required operations without broader access. This approach provides a controlled way to delegate permissions while maintaining security.
SysAdmin permissions model
To grant the Fivetran database user a sysadmin
role in the SQL Server instance, run the following command:
ALTER SERVER ROLE sysadmin ADD MEMBER <loginname>;
Minimal permissions model
You must set up the necessary permissions and create wrapper stored procedures for the minimal user model. The wrapper stored procedures allow Fivetran to interact with designated read-only SQL Server objects required for log-based capture on the source database.
Log on with an sysadmin
account and perform the following steps to set up the minimal user model. Be sure to replace <database_name>
and <username>
with the actual database name and username.
Grant the specified user various permissions, including VIEW SERVER STATE or VIEW SERVER PERFORMANCE STATE based on the SQL Server version and VIEW DEFINITION on the database.
USE [master]; GO DECLARE @sql NVARCHAR(MAX); IF CAST(SERVERPROPERTY('ProductMajorVersion') AS INT) >= 16 SET @sql = 'GRANT VIEW SERVER PERFORMANCE STATE TO <username>;'; ELSE SET @sql = 'GRANT VIEW SERVER STATE TO <username>;'; EXEC sp_executesql @sql; GO -- Need to view which tables are cdc (supplemental logging) enabled GRANT VIEW DEFINITION ON DATABASE::[<database_name>] TO <username>;
Enable the TRUSTWORTHY setting on the database to allow certain operations.
USE [<database_name>]; -- Need to enable trustworthy to allow the user to execute sp_repldone ALTER DATABASE [<database_name>] SET TRUSTWORTHY ON;
Add the Fivetran user to the
db_datareader
role.USE [<database_name>]; ALTER ROLE db_datareader ADD member <username>; GO
Create the following stored procedures required for Fivetran's operations:
sp_fivetran_cdc_enable_db
: Enables Change Data Capture (CDC) on the database.sp_fivetran_cdc_drop_job
: Drops the CDC capture job to reduce disk and CPU utilization.sp_fivetran_cdc_enable_table
: Enables CDC on a specified table for supplemental logging.sp_fivetran_replflush
: Executes the sp_replflush procedure.sp_fivetran_repldone
: Executes the sp_repldone procedure with specified parameters.sp_fivetran_dbcc_loginfo
: Executes the DBCC LOGINFO command.
USE [<database_name>]; IF OBJECT_ID(N'sp_fivetran_cdc_enable_db', 'P') IS NOT NULL DROP PROCEDURE sp_fivetran_cdc_enable_db; GO CREATE PROCEDURE sp_fivetran_cdc_enable_db WITH EXECUTE AS OWNER AS SET NOCOUNT ON EXEC sys.sp_cdc_enable_db; GO IF OBJECT_ID(N'sp_fivetran_cdc_drop_job', 'P') IS NOT NULL DROP PROCEDURE sp_fivetran_cdc_drop_job; GO CREATE PROCEDURE sp_fivetran_cdc_drop_job WITH EXECUTE AS OWNER AS SET NOCOUNT ON EXEC sp_cdc_drop_job @job_type = N'capture' GO IF OBJECT_ID(N'sp_fivetran_cdc_stop_job', 'P') IS NOT NULL DROP PROCEDURE sp_fivetran_cdc_stop_job; GO CREATE PROCEDURE sp_fivetran_cdc_stop_job WITH EXECUTE AS OWNER AS SET NOCOUNT ON EXEC sp_cdc_stop_job @job_type = N'capture' GO IF OBJECT_ID(N'sp_fivetran_cdc_enable_table', 'P') IS NOT NULL DROP PROCEDURE sp_fivetran_cdc_enable_table; GO CREATE PROCEDURE sp_fivetran_cdc_enable_table @source_schema NVARCHAR(500), @source_name NVARCHAR(500), @capture_instance NVARCHAR(500) = NULL, -- Optional; generated if not provided @role_name NVARCHAR(500) = NULL -- Optional WITH EXECUTE AS OWNER AS BEGIN SET NOCOUNT ON; -- Generate the capture instance if not provided IF @capture_instance IS NULL BEGIN SET @capture_instance = N'fivetran_' + CAST(OBJECT_ID(@source_schema + '.' + @source_name) AS NVARCHAR(500)); END; -- Enable CDC for the specified table EXEC sys.sp_cdc_enable_table @source_schema = @source_schema, @source_name = @source_name, @capture_instance = @capture_instance, @role_name = @role_name; END; GO IF OBJECT_ID(N'sp_fivetran_replflush', 'P') IS NOT NULL DROP PROCEDURE sp_fivetran_replflush; GO CREATE PROCEDURE sp_fivetran_replflush WITH EXECUTE AS OWNER AS SET NOCOUNT ON EXEC sp_replflush GO IF OBJECT_ID(N'sp_fivetran_repldone', 'P') IS NOT NULL DROP PROCEDURE sp_fivetran_repldone; GO CREATE PROCEDURE sp_fivetran_repldone @xactid BINARY(10), @xact_seqno BINARY(10), @numtrans INTEGER = NULL, @time INTEGER = NULL, @reset INTEGER = NULL WITH EXECUTE AS SELF AS DECLARE @stmt VARCHAR(200) SET @stmt = 'EXEC sp_repldone ' + '@xactid= ' + CASE WHEN @xactid IS NULL THEN 'NULL' ELSE CONVERT(VARCHAR, @xactid, 1) END + ', @xact_seqno= ' + CASE WHEN @xact_seqno IS NULL THEN 'NULL' ELSE CONVERT(VARCHAR, @xact_seqno, 1) END IF @numtrans IS NOT NULL SET @stmt = @stmt + ', @numtrans= ' + CONVERT(VARCHAR, @numtrans) IF @time IS NOT NULL SET @stmt = @stmt + ', @time= ' + CONVERT(VARCHAR, @time) IF @reset IS NOT NULL SET @stmt = @stmt + ', @reset= ' + CONVERT(VARCHAR, @reset) EXEC(@stmt) GO IF OBJECT_ID(N'sp_fivetran_dbcc_loginfo', 'P') IS NOT NULL DROP PROCEDURE sp_fivetran_dbcc_loginfo; GO CREATE PROCEDURE sp_fivetran_dbcc_loginfo WITH EXECUTE AS OWNER AS SET NOCOUNT ON DBCC LOGINFO GO
Grant the Fivetran user execute permissions on the stored procedures you created in the previous step.
NOTE: You will grant permissions on the
sp_fivetran_readlog
stored procedure in a future step.USE [<database_name>]; GRANT EXECUTE ON sp_fivetran_cdc_enable_db TO <username>; GRANT EXECUTE ON sp_fivetran_cdc_drop_job TO <username>; GRANT EXECUTE ON sp_fivetran_cdc_enable_table TO <username>; GRANT EXECUTE ON sp_fivetran_dbcc_loginfo TO <username>; GRANT EXECUTE ON sp_fivetran_replflush TO <username>; GRANT EXECUTE ON sp_fivetran_repldone TO <username>;
Enable incremental updates
For incremental updates, we use one of the following tracking mechanisms:
These mechanisms let Fivetran copy only the rows that have changed since the last data sync so we don't have to copy the whole table every time. Learn more in our updating data documentation.
Choose to enable change tracking, change data capture, Binary Log Reader, or Fivetran Teleport Sync. Depending on whether you are connecting Fivetran to your primary instance or an availability group replica, you may be limited in the mechanism you can choose. See our Supported Configurations documentation for more information.
Change tracking
Expand for instructions
Enable change tracking at the database level:
ALTER DATABASE [<database>] SET CHANGE_TRACKING = ON (CHANGE_RETENTION = 7 DAYS, AUTO_CLEANUP = ON);
NOTE: While we recommend seven days of change retention, you can set your retention period as low as one day. However, a shorter retention period increases the risk that your logs will expire in between syncs, triggering an automatic full source re-sync.
Enable CT for each table you want to integrate:
ALTER TABLE [<schema>].[<table>] ENABLE CHANGE_TRACKING;
Grant the Fivetran user
VIEW CHANGE TRACKING
permission for each of the tables that have CT enabled:GRANT VIEW CHANGE TRACKING ON [<schema>].[<table>] TO <username>;
Change data capture
Expand for instructions
Enable change data capture at the database level:
USE TEST; EXEC sys.sp_cdc_enable_db;
Enable CDC for each table you want to integrate:
EXEC sys.sp_cdc_enable_table @source_schema = [<schema>], @source_name = [<table>], @role_name = [<username>], @supports_net_changes = 0;
NOTE: Fivetran only supports tables with a single CDC capture instance. Our syncs only include tables and columns that are present in a CDC instance. If you add new tables or columns, you must create a new CDC instance that includes them and delete the old instance.
NOTE: When @supports_net_changes is set to 1, an additional non-clustered index is created on the change table. Because this index needs to be maintained, enabling net changes can degrade CDC performance.
Set the CDC retention period:
EXEC sys.sp_cdc_change_job @job_type = N'cleanup', @retention = 10080; -- Sets the retention period to 7 days
NOTE: While we recommend seven days of change retention, you can set your retention period as low as one day. However, a shorter retention period increases the risk that your logs will expire in between syncs, triggering an automatic full source re-sync.
Set the CDC polling interval:
EXEC sys.sp_cdc_change_job @job_type = N'capture', @pollinginterval = 5; -- in Seconds (5 seconds)
NOTE: We recommend using the default polling interval of 5 seconds. Increasing the polling interval can introduce delays in capturing changes. If the polling interval exceeds the incremental update frequency, changes made during that sync window may not be captured, leading to potential data inconsistencies.
Binary Log Reader Private Preview
Expand for instructions
Acquire the Fivetran Binary Log Reader DLL file from the Fivetran Support team.
Place the Binary Log Reader DLL file on your SQL Server host machine.
Make a note of the directory path to the DLL file (for example,
C:\MSSQL-CLR\Fivetran_Log_Reader.dll
), you’ll need it in the following steps.Connect to your SQL Server database as an admin user to configure the Binary Log Reader. You must use the same admin user that you’ll use to create the connector. Using the admin user is a one-time requirement during the installation.
Run the following SQL command to enable CLR on your SQL Server database. Perform this step once for each database host.
IMPORTANT: If CLR is already enabled on your SQL Server database, skip ahead to step 5 (sign the DLL) in this section. To check whether you have CLR enabled, run the
SELECT * FROM sys.configurations WHERE name = 'clr enabled'
command.use master if (SELECT value_in_use FROM sys.configurations WHERE name = 'clr enabled') = 0 BEGIN EXEC sp_configure 'clr enabled', 1; RECONFIGURE; END;
Run the following SQL command to sign the DLL. Perform this step once for each database host. Replace
'{Path to Fivetran Binary Log Reader DLL}'
with the full directory path to the Fivetran Binary Log Reader DLL file on your SQL Server host machine.use master; IF EXISTS (SELECT * FROM sys.server_principals WHERE name = 'FivetranUser') BEGIN DROP LOGIN FivetranUser END IF EXISTS (SELECT * FROM sys.asymmetric_keys WHERE name = 'FivetranCLRKey') BEGIN DROP ASYMMETRIC KEY FivetranCLRKey END IF NOT EXISTS (SELECT * FROM sys.asymmetric_keys WHERE name = 'FivetranCLRKey') BEGIN CREATE ASYMMETRIC KEY FivetranCLRKey FROM EXECUTABLE FILE = '{Path to Fivetran Binary Log Reader DLL}'; END;
Run the following SQL command to create a login for the Fivetran user from the asymmetric key and grant it the
UNSAFE ASSEMBLY
permission. Perform this step once for each database host.use master IF NOT EXISTS (SELECT * FROM sys.server_principals WHERE name = 'FivetranUser') BEGIN CREATE LOGIN FivetranUser FROM ASYMMETRIC KEY FivetranCLRKey; GRANT UNSAFE ASSEMBLY TO FivetranUser ; END
Create a stored procedure on your database that knows how to call the log reader DLL. Perform this step once for each database that you want to sync with Fivetran. For example, if you have two databases called
sales
andanalytics
on the same SQL Server instance, run the following commands twice - first by replacing<database>
withsales
, then withanalytics
.i. Run the following SQL command to create the assembly that the stored procedure will execute. Replace
<database>
with the name of your database and'{Path to Fivetran Binary Log Reader DLL}'
with the full directory path to the Fivetran Binary Log Reader DLL file on your SQL Server host machine.USE <database>; IF EXISTS (SELECT * FROM sys.assemblies WHERE name = 'Fivetran') BEGIN DROP PROCEDURE sp_Fivetran_ReadLog DROP ASSEMBLY Fivetran END CREATE ASSEMBLY Fivetran FROM '{Path to Fivetran Binary Log Reader DLL}' WITH PERMISSION_SET = UNSAFE;
ii. Run the following SQL command to link the stored procedure to the assembly (created in the previous step) so that invocations of the stored procedure will call the assembly.
CREATE OR ALTER PROCEDURE sp_Fivetran_ReadLog (@process int, @handle bigint, @offset bigint, @bufSize int, @parity tinyint, @filter varbinary(1000) = null) AS EXTERNAL NAME Fivetran.LogReader.sp_Fivetran_ReadLog;
NOTE: Once you complete this step, the DLL/stored procedure is operable by Fivetran.
(Minimal permissions model only) Grant the Fivetran user execute permissions on the
sp_fivetran_readlog
stored procedure you created in the Grant user permissions step.GRANT EXECUTE ON sp_fivetran_readlog TO <username>;
Fivetran Teleport Sync
You do not need to do any additional configuration to use Fivetran Teleport Sync.
(Optional) Schema changes for change tracking (CT) and change data capture (CDC) Beta
By default, when you create a new table in your database, you must manually enable CT or CDC for that table before we can sync it. Additionally, if you add a new column to an existing CDC-enabled table, you must manually recreate the CDC capture instance before we can sync the column.
If you want Fivetran to automatically enable CT or CDC for newly created tables and to update CDC capture instances when a new column is added, install the following stored procedures on your database. If your connector contains only CT-enabled tables, then any subsequent new tables will be CT-enabled. If your connector has a mixture of CT- and CDC-enabled tables or contains CDC-enabled tables only, then we will enable CDC over CT by default.
Expand for instructions
Install the following script on your database. Before running the script, replace
<database>
with your database name.NOTE: If you have configured your connector to "Allow columns", you can exclude the
[dbo].[sp_ft_enable_cdc]
and[dbo].[sp_ft_enable_change_tracking]
stored procedures. If you have configured your connector to "Block All", you can exclude all the following stored procedures.USE [<database>]; /****** Object: StoredProcedure [dbo].[sp_ft_enable_cdc] Script Date: 1/17/2024 11:12:55 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[sp_ft_enable_cdc] @TableList NVARCHAR(MAX), @FivetranUser NVARCHAR(MAX) WITH EXECUTE AS OWNER -- Change to an appropriate sysadmin user AS BEGIN SET NOCOUNT ON; -- Table to store tables with results CREATE TABLE #ResultTables (TableName NVARCHAR(MAX), Result NVARCHAR(MAX)); -- Enable CDC for each table DECLARE @TableName NVARCHAR(MAX); DECLARE @SqlStatement NVARCHAR(MAX); WHILE LEN(@TableList) > 0 BEGIN -- Get the first table in the list SET @TableName = NULL; SET @TableName = SUBSTRING(@TableList, 1, CHARINDEX(',', @TableList + ',') - 1); -- Remove the processed table from the list SET @TableList = STUFF(@TableList, 1, LEN(@TableName) + 1, ''); -- Build and execute the SQL statement to enable CDC for the table SET @SqlStatement = ' BEGIN TRY EXEC sys.sp_cdc_enable_table @source_schema = ''' + PARSENAME(@TableName, 2) + ''', @source_name = ''' + PARSENAME(@TableName, 1) + ''', @role_name = ''' + @FivetranUser + ''', @supports_net_changes = 0; INSERT INTO #ResultTables (TableName, Result) VALUES (''' + @TableName + ''', ''Success''); END TRY BEGIN CATCH PRINT ERROR_MESSAGE(); INSERT INTO #ResultTables (TableName, Result) VALUES (''' + @TableName + ''', ERROR_MESSAGE()); END CATCH '; -- Execute the dynamic SQL statement EXEC sp_executesql @SqlStatement; END -- Return the list of tables with results SELECT * FROM #ResultTables; -- Drop the temporary table DROP TABLE #ResultTables; END; GO /****** Object: StoredProcedure [dbo].[sp_ft_enable_change_tracking] Script Date: 1/17/2024 11:10:45 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[sp_ft_enable_change_tracking] @TableList NVARCHAR(MAX), @FivetranUser NVARCHAR(MAX) WITH EXECUTE AS OWNER -- Change to an appropriate sysadmin user AS BEGIN SET NOCOUNT ON; -- Table to store tables with results CREATE TABLE #ResultTables (TableName NVARCHAR(MAX), Result NVARCHAR(MAX)); -- Enable change tracking for each table DECLARE @TableName NVARCHAR(MAX); DECLARE @SqlStatement NVARCHAR(MAX); WHILE LEN(@TableList) > 0 BEGIN -- Get the first table in the list SET @TableName = NULL; SET @TableName = SUBSTRING(@TableList, 1, CHARINDEX(',', @TableList + ',') - 1); -- Remove the processed table from the list SET @TableList = STUFF(@TableList, 1, LEN(@TableName) + 1, ''); -- Build and execute the SQL statement to enable change tracking SET @SqlStatement = ' BEGIN TRY ALTER TABLE ' + @TableName + ' ENABLE CHANGE_TRACKING; GRANT VIEW CHANGE TRACKING ON ' + @TableName + ' TO ' + @FivetranUser + '; INSERT INTO #ResultTables (TableName, Result) VALUES (''' + @TableName + ''', ''Success''); END TRY BEGIN CATCH PRINT ERROR_MESSAGE(); INSERT INTO #ResultTables (TableName, Result) VALUES (''' + @TableName + ''', ERROR_MESSAGE()); END CATCH '; -- Execute the dynamic SQL statement EXEC sp_executesql @SqlStatement; END -- Return the list of tables with results SELECT * FROM #ResultTables; -- Drop the temporary table DROP TABLE #ResultTables; END; GO /****** Object: StoredProcedure [dbo].[sp_ft_get_tables_with_ddl_changes] Script Date: 1/30/2024 9:10:47 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[sp_ft_get_tables_with_ddl_changes] @TableList NVARCHAR(MAX), @ddlTime DATETIME = NULL -- New parameter for ddlTime WITH EXECUTE AS OWNER -- Change to an appropriate sysadmin user AS BEGIN SET NOCOUNT ON; -- Declare a table variable to store the results DECLARE @ChangedTables TABLE ( TableName NVARCHAR(MAX), DdlTime DATETIME ); -- Split the comma-separated list into a table variable DECLARE @TableNames TABLE ( TableName NVARCHAR(MAX) ); INSERT INTO @TableNames (TableName) SELECT value FROM STRING_SPLIT(@TableList, ','); -- Check for DDL changes in cdc.ddl_history INSERT INTO @ChangedTables (TableName, DdlTime) SELECT tn.TableName, MAX(dh.ddl_time) AS LatestDdlTime FROM cdc.ddl_history dh INNER JOIN @TableNames tn ON CONCAT(OBJECT_SCHEMA_NAME(dh.source_object_id), '.', OBJECT_NAME(dh.source_object_id)) = tn.TableName WHERE @ddlTime IS NULL OR dh.ddl_time >= @ddlTime GROUP BY tn.TableName; -- Return the list of tables with the latest DDL changes SELECT TableName, DdlTime FROM @ChangedTables; END; GO /****** Object: StoredProcedure [dbo].[sp_ft_update_cdc] Script Date: 1/31/2024 1:19:40 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE OR ALTER PROCEDURE [dbo].[sp_ft_update_cdc] @TableName NVARCHAR(MAX), @FivetranUser NVARCHAR(MAX), @CaptureInstance NVARCHAR(MAX), @CapturedColumnList NVARCHAR(MAX) WITH EXECUTE AS OWNER AS BEGIN SET NOCOUNT ON; -- Table to store tables with results CREATE TABLE #ResultTables (TableName NVARCHAR(MAX), Result NVARCHAR(MAX)); DECLARE @SourceSchema NVARCHAR(MAX); DECLARE @SourceName NVARCHAR(MAX); BEGIN TRY -- Assign values to variables for PARSENAME function SET @SourceSchema = PARSENAME(@TableName, 2); SET @SourceName = PARSENAME(@TableName, 1); -- Step 1: Disable the current CDC instance EXEC sys.sp_cdc_disable_table @source_schema = @SourceSchema, @source_name = @SourceName, @capture_instance = @CaptureInstance; -- Step 2: Create a new CDC instance EXEC sys.sp_cdc_enable_table @source_schema = @SourceSchema, @source_name = @SourceName, @role_name = @FivetranUser, @capture_instance = @CaptureInstance, @captured_column_list = @CapturedColumnList, @supports_net_changes = 0; -- Insert the result into the #ResultTables table INSERT INTO #ResultTables (TableName, Result) VALUES (@TableName, 'Success'); END TRY BEGIN CATCH PRINT ERROR_MESSAGE(); -- Insert the error message into the #ResultTables table INSERT INTO #ResultTables (TableName, Result) VALUES (@TableName, ERROR_MESSAGE()); END CATCH; -- Return the list of tables with results SELECT * FROM #ResultTables; -- Drop the temporary table DROP TABLE #ResultTables; END; GO
Grant the Fivetran user execute permission.
USE [<database>]; GRANT EXECUTE ON dbo.sp_ft_enable_cdc to <username>; GRANT EXECUTE ON dbo.sp_ft_enable_change_tracking to <username>; GRANT EXECUTE ON dbo.sp_ft_get_tables_with_ddl_changes to <username>; GRANT EXECUTE ON dbo.sp_ft_update_cdc to <username>;
Finish Fivetran configuration
In your connection setup form, enter a Destination schema prefix. This is used as the connection name and cannot be modified once the connection is created.
NOTE: Depending on your selection in the Destination schema names field, we will either prefix the connection name to each replicated schema or use the source schema names instead.
In the Host field, enter your database host's IP (for example,
1.2.3.4
) or domain (for example,your.server.com
).Enter your database instance's port number. The port number is usually
1433
.Enter the Fivetran-specific user that you created in Step 3.
Enter the password for the Fivetran-specific user that you created in Step 3.
Enter the name of your database (for example,
your_database
).(Hybrid Deployment only) If your destination is configured for Hybrid Deployment, the Hybrid Deployment Agent associated with your destination is pre-selected in the Select an existing agent drop-down menu. To use a different agent, select the agent of your choice, and then select the same agent for your destination.
(Not applicable to Hybrid Deployment) Choose your connection method. If you selected Connect via an SSH tunnel, copy or make a note of the Public Key and add it to the
authorized_keys
file while configuring the SSH tunnel, and provide the following information:- SSH hostname (do not use a load balancer's IP address/hostname)
- SSH port
- SSH user
- If you enabled TLS on your database in Step 1, make sure to keep the Require TLS through Tunnel toggle turned ON.
(Optional for Hybrid Deployment) If you want to use a TLS connection between your Hybrid Deployment Agent and Fivetran cloud, set the Require TLS toggle to ON.
IMPORTANT: Before you set this toggle to ON, follow Microsoft's setup instructions to enable TLS on your database. We do not support TLS 1.0.
Choose your incremental Update Method.
In the Destination schema names field, select Fivetran naming or Source naming to determine how the schema names appear in your destination. For more information, see the Schema information section.
Click Save & Test. Fivetran tests and validates our connection to your SQL Server database. Upon successful completion of the setup tests, you can sync your data using Fivetran.
Setup tests
Fivetran performs the following tests to ensure that we can connect to your generic SQL Server database and that it is properly configured:
- The Connecting to SSH Tunnel Test validates the SSH tunnel details you provided in the setup form. It then checks that we can connect to your database using the SSH Tunnel. (We skip this test if you aren't connecting using SSH.)
- The Connecting to Host Test validates the database credentials you provided in the setup form. It then verifies that the database host is not private and checks that we can connect to the host.
- The Validating Certificate Test generates a pop-up window where you must choose which certificate you want Fivetran to use. It then validates that certificate and checks that we can connect to your database using TLS. (We skip this test if you selected an indirect connection method and then disabled the Require TLS through Tunnel toggle.)
- The Connecting to Database Test checks that we can access your database.
- The Checking Access to Schema Test checks that we have the correct permissions to access the schemas in your database. It then verifies that your database contains at least one table.
- The Validating Replication Config Test verifies that your database has an incremental sync method enabled (either CDC or CT).
NOTE: The tests may take a few minutes to finish running.
Related articles
description Connector Overview
account_tree Schema Information
settings API Connection Configuration