Azure SQL Managed Instance
Setup guide for Azure SQL Managed Instance as a Streamkap source, covering the public endpoint, sysadmin requirement, CDC activation, and sharing CDC with other tools.
Prerequisites
- An Azure SQL Managed Instance. SQL Server Agent is always running on Managed Instance, and it runs the change data capture (CDC) capture and cleanup jobs.
- A login in the
sysadminserver role to enable CDC on the database. Enabling CDC on individual tables needs thedb_ownerdatabase role.
Managed Instance Setup
1. Grant Database Access
Choose how Streamkap reaches your Managed Instance:
Managed Instance serves public connections on port 3342, not 1433. The port can’t be changed.
- In the Azure portal, open the Managed Instance and go to Security > Networking. Under Public endpoint (data), select Enable, then save.
- In the network security group (NSG) on the Managed Instance subnet, add an inbound Allow rule for TCP port
3342from the Streamkap IP addresses. Give it a higher priority than thedeny_all_inboundrule. - Use the public endpoint hostname, which has the form
{mi_name}.public.{dns_zone}.database.windows.net. The Azure portal shows it on the Managed Instance Connection strings page.
Connect over a private network route, such as Private Link or VNet peering, to the Managed Instance’s private hostname {mi_name}.{dns_zone}.database.windows.net on port 1433. See Connection Options.
2. Enable Change Data Capture
Connected as a sysadmin login, enable CDC on the database:
-- Replace { ... } placeholders as required
USE [{database}];
EXEC sys.sp_cdc_enable_db;
GOFor every table you want Streamkap to capture, enable CDC on that table:
-- Replace { ... } placeholders as required
USE [{database}];
EXEC sys.sp_cdc_enable_table
@source_schema = N'{schema}',
@source_name = N'{table}',
@role_name = N'streamkap_role',
@supports_net_changes = 0
GOIf a table already has CDC enabled, for example because another tool reads it, don’t enable it again. See Sharing CDC with another tool.
3. Create Database User
Create a separate login, user, and role for Streamkap. Add one GRANT SELECT ON SCHEMA line for each schema you want to capture.
-- Replace {database}, {schema} and {password} placeholders as required
USE master;
GO
CREATE LOGIN streamkap_user WITH PASSWORD = '{password}';
GRANT VIEW SERVER STATE TO streamkap_user; -- Used for monitoring the SQL Server Agent service state
GO
USE [{database}];
GO
CREATE USER streamkap_user FOR LOGIN streamkap_user;
IF DATABASE_PRINCIPAL_ID('streamkap_role') IS NULL CREATE ROLE streamkap_role; -- CDC may have created it already
ALTER ROLE streamkap_role ADD MEMBER streamkap_user;
GRANT SELECT ON SCHEMA::{schema} TO streamkap_role; -- Repeat for each captured schema
GRANT SELECT ON SCHEMA::cdc TO streamkap_role;
GO4. Enable Snapshots
To backfill your data, the Connector needs to be able to perform snapshots (See Snapshots & Backfilling for more information). To enable this process, a table must be created for the Connector to use.
-- Replace {database} placeholder as required
USE [{database}];
GO
CREATE SCHEMA streamkap;
GO
-- Create the table within the schema
CREATE TABLE streamkap.streamkap_signal (
id VARCHAR(255) PRIMARY KEY,
type VARCHAR(32) NOT NULL,
data VARCHAR(2000) NULL
);
-- Enable change data capture on the signal table
EXEC sys.sp_cdc_enable_table
@source_schema = N'streamkap',
@source_name = N'streamkap_signal',
@role_name = N'streamkap_role',
@supports_net_changes = 0
GO
-- Grant permission on the signal table to the Streamkap role
GRANT SELECT, UPDATE, INSERT, DELETE ON streamkap.streamkap_signal TO streamkap_role;5. Heartbeats
Connectors use “offsets”—like bookmarks—to track their position in the database’s log or change stream. When no changes occur for long periods, these offsets may become outdated, and the Connector might lose its place or stop capturing changes.
Heartbeats ensure the Connector stays active and continues capturing changes.
There are two layers of heartbeat protection:
Layer 1: Connector heartbeats (enabled by default)
The Connector periodically emits heartbeat messages to an internal topic, even when no actual data changes are detected. This keeps offsets fresh and prevents staleness.
No configuration is necessary for this layer; it is automatically enabled. We recommend keeping this layer enabled for all deployments.
Layer 2: Source database heartbeats (recommended)
You can configure regular updates to a dedicated heartbeat table in the source database. This simulates activity, ensuring change events are generated consistently, maintaining log progress and providing additional resilience.
How this layer is configured depends on the connection type (if supported by the Source):
- Read-write connections (when Read only is No during Streamkap Setup): The Connector updates the heartbeat table directly.
- Read-only connections (when Read only is Yes during Streamkap Setup): A scheduled job on the primary database updates the heartbeat table, and these changes replicate to the read replica for the Connector to consume.
This layer requires you to set up a heartbeat table—and for read-only connections, a scheduled job (e.g., pg_cron for PostgreSQL, event_scheduler for MySQL)—on your source database.
For read-write connections (when Read only is No during Streamkap Setup), the Connector writes to the heartbeat table directly.
-- Create the heartbeat table with id, text, and last_update fields
CREATE TABLE streamkap.streamkap_heartbeat (
id INT IDENTITY(1,1) PRIMARY KEY,
text NVARCHAR(MAX),
last_update DATETIME2 DEFAULT SYSUTCDATETIME()
);
-- Enable change tracking on the heartbeat table
EXEC sys.sp_cdc_enable_table
@source_schema = N'streamkap',
@source_name = N'streamkap_heartbeat',
@role_name = N'streamkap_role',
@supports_net_changes = 0
GO
-- Grant permission on the heartbeat table to the Streamkap role
GRANT SELECT, UPDATE, INSERT, DELETE ON streamkap.streamkap_heartbeat TO streamkap_role;
-- Insert the first row into the heartbeat table
INSERT INTO streamkap.streamkap_heartbeat (text) VALUES ('test_heartbeat');Sharing CDC with another tool
If another tool, such as a replication or ETL product, already reads CDC from this database, Streamkap can read the same capture instances without changing them. Reading change tables doesn’t consume or remove rows, so both tools see every change.
Check the existing capture instances first:
USE [{database}];
EXEC sys.sp_cdc_help_change_data_capture;
GOrole_name: If a capture instance has a gating role,streamkap_usermust be a member of it, or reads from that change table return no rows. RunALTER ROLE {role_name} ADD MEMBER streamkap_user;.captured_column_list: If the instance was created with a column list, Streamkap only sees those columns.- Two capture instances per table: SQL Server allows at most 2 capture instances per table, and both tools share that limit. When a table’s structure changes, the Connector switches to the newest capture instance. Agree one process for refreshing change tables with the other tool’s owners. See Table schema evolution.
- Retention: The CDC cleanup job and its retention apply to the whole database, so both tools share them. Raising retention is safe for both tools and only costs storage. Lowering it can remove changes the other tool hasn’t read yet. The default is 3 days (4320 minutes).
-- Check the current capture and cleanup job settings
USE [{database}];
EXEC sys.sp_cdc_help_jobs;
GO
-- Raise retention, in minutes (example: 7 days)
EXEC sys.sp_cdc_change_job @job_type = N'cleanup', @retention = 10080;
GOLeave the capture job settings (maxtrans, maxscans, pollinginterval) as they are unless both tools’ owners agree. Both tools depend on them.
Streamkap Setup
Follow these steps to configure your new connector:
1. Create the Source
- Navigate to Add Connectors.
- Choose SQL Server.
2. Connection Settings
-
Name: Enter a name for your connector.
-
Endpoint: The Managed Instance hostname. For the public endpoint, use
{mi_name}.public.{dns_zone}.database.windows.net. -
Port:
3342for the public endpoint,1433for private connectivity. -
Connect via SSH Tunnel: The Connector will connect to an SSH server in your network which has access to your database. This is necessary if the Connector cannot connect directly to your database.
- See SSH Tunnel for setup instructions.
-
Username: Username to access the database. By default, Streamkap scripts use
streamkap_user. -
Password: Password to access the database.
-
Source Database: Specify the database to stream data from.
-
Heartbeats:
- Heartbeat Table Schema: Streamkap will use a table in this schema to manage heartbeats. Usually this is the same as the Signal Table. See Heartbeats for setup instructions.
3. Snapshot Settings
- Signal Table: Full path to the signal table including schema and table name (e.g.,
streamkap.streamkap_signal). This table is used for incremental snapshotting. See Enable Snapshots for setup instructions.
4. Advanced Parameters
- Represent binary data as: Specifies how the data for binary columns e.g.
blob,binary,varbinaryshould be interpreted. Your destination for this data can impact which option you choose. Default isbytes. - Capture Only Captured Databases DDL (Default
false) - Specifies whether the connector records schema structures from all databases defined in the server (the default) or only those databases for which you’ve explicitly configured the connector. Specifytrueto capture schema history only for the specific databases you’ve configured. This is particularly valuable when databases are large, to reduce the volume of DDL stored in the schema history topic. It also improves startup times when the connector restarts or recovers from failures. See Schema History Optimization for details. - Capture Only Captured Tables DDL (Default
false) - Specifies whether the connector records the schema structure for all tables in the configured databases (the default) or only the tables whose changes the connector captures. Specifytrueto capture schema history only for the specific tables you’ve configured. This is particularly valuable when tables are large, to reduce the volume of DDL statements stored in the schema history topic. It also improves startup times when the connector restarts or recovers from failures. See Schema History Optimization for details.
Click Next.
5. Schema and Table Capture
- Add Schemas/Tables: Specify the schema(s) and table(s) for capture
- You can bulk upload here. The format is a simple list of schemas and tables, with each entry on a new row. Save as a
.csvfile without a header.
- You can bulk upload here. The format is a simple list of schemas and tables, with each entry on a new row. Save as a
Click Save.
Troubleshooting
Table schema evolution and change tracking tables
When CDC is enabled for a table and changes occur to it, change events are persisted to a ‘change table’ on the SQL Server database server.
If you introduce a change in the structure of the source table, for example, by adding a new column, that change is not reflected in the change table.
For as long as the change table continues to use the outdated table structure, the Streamkap SQL Server Source is unable to capture change events for the table correctly.
You must intervene to refresh the change table structure because of the way that CDC is implemented in SQL Server.
Refresh change table structure (Online)
If another tool also reads CDC from this table, agree the refresh with its owners first. See Sharing CDC with another tool.
For every source table that has changed, copy paste the script below into SQL Server Management Studio, change placeholders as required, and then run all queries.
-- Replace {database}, {schema} and {table} placeholders
-- {database}: name of the CDC enabled database
-- {schema}: name of the schema with tables to refresh
-- {table}: name of the table to refresh
-- {refresh_table}: a unique name for the refreshed change table
USE [{database}];
GO
EXEC sys.sp_cdc_enable_table
@source_schema = N'{schema}',
@source_name = N'{table}',
@role_name = N'streamkap_role',
@supports_net_changes = 0,
@capture_instance = N'{refresh_table}'
GOTwo capture instances already exist for source table
If you’re getting this error message when refreshing the change table structure, it’s because there cannot be more than 2 change tables for every source table.
To fix the problem, 1 of the 2 change tables for the source table need to be disabled. If another tool uses one of them, check with its owners before disabling anything. The scripts below can help you do that.
-- Replace {database}, {schema} and {table} placeholders
USE [{database}];
GO
EXEC sys.sp_cdc_help_change_data_capture
@source_schema = N'{schema}',
@source_name = N'{table}'
GOThe above script should return 2 results, the 2 change tables for the {table} specified. Typically you would disable the oldest change table, so use the create_date column to identify the oldest one.
When you’ve identified the change table to disable, use its source_schema, source_table and capture_instance names in the query below and execute. Then, try your refresh table script again.
-- Replace {database}, {source_schema}, {source_table} and {capture_instance} placeholders
USE [{database}];
GO
EXEC sys.sp_cdc_disable_table
@source_schema = N'{source_schema}',
@source_name = N'{source_table}',
@capture_instance = N'{capture_instance}'
GOThe Connector's running but there is no data
There can be a number of reasons. The most common are misconfiguration of CDC and privilege grants.
To diagnose, run the following script:
-- Replace {database} placeholder
USE [{database}];
GO
EXEC sys.sp_cdc_help_change_data_capture;
EXEC sys.sp_cdc_help_jobs;
SELECT * FROM sys.dm_cdc_errors;
GOIf the query returns an error or no results check:
- you are connected with a user that has
db_ownerrole privileges. - if
sys.sp_cdc_help_change_data_capturereturns no results, the source tables you want Streamkap to capture may not be CDC enabled. - if
sys.sp_cdc_help_jobsreturns no results, the CDC capture and cleanup jobs are missing. Recreate the missing one withEXEC sys.sp_cdc_add_job @job_type = N'capture';orN'cleanup'. Don’t disable and re-enable CDC on the database to fix this: that drops every capture instance, including ones other tools use.
If the query returns results, check:
- the table(s) captured by the Connector are listed.
- there are
capture_instances for the capture tables. streamkap_useris a member of therole_namefor each captured table, including capture instances another tool created.sys.dm_cdc_errorsshows no recent capture errors.
If you are still having issues after following the above steps, please don’t hesitate to reach out to us.
The setup scripts are failing
sp_cdc_enable_dbfails with a permissions error: the login isn’t in thesysadminserver role. On Managed Instance, enabling CDC on the database needssysadmin, notdb_owner.ALTER DATABASE ... ADD FILEfails: Managed Instance doesn’t accept aFILENAME. You don’t need a separate filegroup; leave out@filegroup_name.
To check the database state, run:
-- Replace {database} placeholder
USE [{database}];
GO
SELECT name, compatibility_level, is_read_only, state_desc, is_cdc_enabled
FROM sys.databases
WHERE name = '{database}';
EXEC sys.sp_cdc_help_change_data_capture;
GOIf is_cdc_enabled is 0, CDC isn’t enabled on the database. CDC is also disabled after a point-in-time restore into a new database, so re-enable it there.
If you are still having issues after following the above steps, please don’t hesitate to reach out to us.
Can't connect on port 1433 or 3342
- Public endpoint: confirm it’s enabled, the NSG rule allows port
3342from the Streamkap IP addresses abovedeny_all_inbound, and the hostname includes.public.. - Private connectivity: use port
1433and the hostname without.public..