---
title: "Azure SQL Managed Instance"
description: "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 `sysadmin` server role to enable CDC on the database. Enabling CDC on individual tables needs the `db_owner` database role.

:::info
This guide is for **Azure SQL Managed Instance**. For single databases and elastic pools, see [Azure SQL Database](/sql-server-on-azure-sql-database). For SQL Server on an Azure virtual machine, see [SQL Server (Generic)](/sql-server-generic).
:::

## Managed Instance Setup

### 1. Grant Database Access

Choose how Streamkap reaches your Managed Instance:

**Public endpoint**

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 `3342` from the [Streamkap IP addresses](/connection-options). Give it a higher priority than the `deny_all_inbound` rule.
* 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.

**Private connectivity**

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](/connection-options).

### 2. Enable Change Data Capture

Connected as a `sysadmin` login, enable CDC on the database:

```sql SQL
-- Replace { ... } placeholders as required
USE [{database}];
EXEC sys.sp_cdc_enable_db;
GO
```

For every table you want Streamkap to capture, enable CDC on that table:

```sql SQL
-- 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
GO
```

:::note
**No filegroup step**

Managed Instance places database files itself and rejects `ALTER DATABASE ... ADD FILE` with a `FILENAME`. The scripts on this page leave out `@filegroup_name`, so change tables go to the default filegroup.
:::

If a table already has CDC enabled, for example because another tool reads it, don't enable it again. See [Sharing CDC with another tool](#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.

```sql SQL
-- 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;
GO
```

:::info
Use SQL authentication for Managed Instance. Microsoft Entra service principal authentication is supported for [Azure SQL Database](/sql-server-on-azure-sql-database) only. Contact us if you need Entra authentication on Managed Instance.
:::

### 4. Enable Snapshots

To backfill your data, the Connector needs to be able to perform **snapshots** (See [Snapshots & Backfilling](/snapshots) for more information). To enable this process, a table must be created for the Connector to use.

:::info
The examples below use `streamkap_signal` as the signal table name, but you can choose any name. During [Streamkap Setup](#3-snapshot-settings), provide the full path to your signal table in `schema.table` format (e.g., `streamkap.streamkap_signal`).
:::

```sql SQL
-- 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

import Callout from 'blume/components/content/Callout.astro';

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)

:::info
**Why we recommend configuring Layer 2**

While Layer 2 is **crucial** for low-traffic or intermittent databases, we recommend configuring it for all deployments. It provides additional resilience and helps prevent issues during periods of inactivity.
:::

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.

**Read-write connections**

import CodeGroup from 'blume/components/content/CodeGroup.astro';

For read-write connections (when **Read only** is **No** during Streamkap Setup), the Connector writes to the heartbeat table directly.

```sql SQL
-- 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:

```sql SQL
USE [{database}];
EXEC sys.sp_cdc_help_change_data_capture;
GO
```

* **`role_name`**: If a capture instance has a gating role, `streamkap_user` must be a member of it, or reads from that change table return no rows. Run `ALTER 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](#troubleshooting).
* **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).

```sql SQL
-- 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;
GO
```

Leave 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](https://app.streamkap.com/connectors/add?tab=Sources).
* 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**: `3342` for the public endpoint, `1433` for 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](/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](#5-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](#4-enable-snapshots) for setup instructions.

### 4. Advanced Parameters

* **Represent binary data as**: Specifies how the data for binary columns e.g. `blob`, `binary`, `varbinary` should be interpreted. Your destination for this data can impact which option you choose. Default is `bytes`.
* **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. Specify `true` to 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](/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. Specify `true` to 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](/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 `.csv` file without a header.

:::warning
**CDC only captures base tables, not Views**

Change Data Capture reads SQL Server CDC change tables, which only track changes to physical base tables. Database Views are query-time computations with no physical storage—they don't have CDC change tables.

**What you cannot capture:** Views, indexed views (materialized views), table variables, temporary tables, or system tables.

**Solution:** Specify only the underlying base tables that feed your views. You can recreate the view logic in your destination or transformation layer.
:::

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)

:::warning
**Online refresh limitation**

In the interval between the source table structure changing in the source database, and _before_ the change table structure is refreshed, change events continue to be captured with the **outdated** table structure.

For example, if you added a new column to a source table, change events that are captured before the change table is refreshed will not contain the new column.

If this cannot be tolerated, an **Offline** refresh has to be performed. However, that means downtime for whatever system made structural changes to your tables **and** your Streamkap pipelines.

Please contact us for assistance if an Offline refresh is required.
:::

If another tool also reads CDC from this table, agree the refresh with its owners first. See [Sharing CDC with another tool](#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.

:::success
If you're not sure what `{refresh_table}` name to use, use `{schema}_{table}_v{N}`. For example, if the source table is `sales.orders` then you'd use `sales_orders_v2`
:::

```sql SQL
-- 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}'
GO
```

:::danger
**Refresh table limitation**

There cannot be more than 2 change tables for every source table.

After refreshing a change table using the above script, confirm with Streamkap Support that your SQL Server Source has started streaming from the refreshed change table. Once confirmed, disable CDC on the outdated change table. Use the script below to do that.

```sql SQL
-- Replace {database}, {schema}, {table} and {refresh_table} placeholders
-- {database}: name of the CDC enabled database
-- {schema}: name of the schema with the table refreshed earlier
-- {table}: name of the table refreshed earlier
-- {refresh_table}: name of the previous refresh table, usually {schema}_{table}
USE [{database}];
GO
EXEC sys.sp_cdc_disable_table
@source_schema        = N'{schema}',
@source_name          = N'{table}',
@capture_instance     = N'{refresh_table}'
GO
```
:::

**Two 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.

```sql SQL
-- 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}'
GO
```

The 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.

```sql SQL
-- 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}'
GO
```

**The 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:

```sql SQL
-- 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;
GO
```

If the query returns an **error** or **no results** check:

* you are connected with a user that has `db_owner` role privileges.
* if `sys.sp_cdc_help_change_data_capture` returns **no results**, the source tables you want Streamkap to capture may not be CDC enabled.
* if `sys.sp_cdc_help_jobs` returns **no results**, the CDC capture and cleanup jobs are missing. Recreate the missing one with `EXEC sys.sp_cdc_add_job @job_type = N'capture';` or `N'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_instance`s for the capture tables.
* `streamkap_user` is a member of the `role_name` for each captured table, including capture instances another tool created.
* `sys.dm_cdc_errors` shows 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_db` fails with a permissions error: the login isn't in the `sysadmin` server role. On Managed Instance, enabling CDC on the database needs `sysadmin`, not `db_owner`.
* `ALTER DATABASE ... ADD FILE` fails: Managed Instance doesn't accept a `FILENAME`. You don't need a separate filegroup; leave out `@filegroup_name`.

To check the database state, run:

```sql SQL
-- 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;
GO
```

If `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 `3342` from the Streamkap IP addresses above `deny_all_inbound`, and the hostname includes `.public.`.
* Private connectivity: use port `1433` and the hostname without `.public.`.
