Home / Databases / SQL Server

DatabasesRunbookIntermediate

Replicate SQL Server to Microsoft Fabric with mirroring: step by step for SQL Server 2016-2022 (CDC) and 2025 (change feed)

A hands-on runbook to mirror an on-premises SQL Server database into Microsoft Fabric OneLake - gateway, logins, CDC or Azure Arc, the portal steps, checks that replication is healthy, and the limits that break it.

Deepak Bhardwaj9 min read

Applies toSQL Server 2016-2022 (CDC-based) and SQL Server 2025 (change feed, Azure Arc) mirrored into Microsoft Fabric; check Microsoft Learn for current support status

The goal

You want SQL Server tables available in Microsoft Fabric for reporting and analytics, kept close to real time, without building and running ETL pipelines. Fabric mirroring does this. It takes an initial snapshot of the selected tables and then continuously replicates changes into OneLake as Delta tables. You can query them through the SQL analytics endpoint, Power BI or Spark.

How the changes are captured depends on the SQL Server version:

Source version How changes are captured Azure Arc Key requirement
SQL Server 2016-2022 Change Data Capture (CDC), enabled by Fabric on each table Not needed SQL Server Agent running; every table needs a primary key
SQL Server 2025 Change feed built into the engine Required CDC must not be enabled on the database

This post is the hands-on setup. For why you'd replace reporting replicas or ETL with mirroring, see From reporting replicas to Microsoft Fabric.

Warning

Support rules change quickly. At the time of writing, mirroring from SQL Server 2025 isn't supported for instances on an Azure VM or on Linux. Check the Microsoft Learn limitations page for your version before you plan the project.

Step 1: Check the prerequisites

On the Fabric side:

  • An active Fabric capacity. If the capacity is paused or deleted, replication stops.
  • A workspace where you have the Admin or Member role. Contributor isn't enough to create the mirror.
  • In the tenant admin settings, turn on Service principals can use Fabric APIs and Users can access data stored in OneLake with apps external to Fabric.

On the SQL Server side, run these checks:

-- Version and edition
SELECT SERVERPROPERTY('ProductVersion') AS Version,
       SERVERPROPERTY('Edition')        AS Edition;

-- Delayed durability blocks mirroring - must be DISABLED
SELECT name, delayed_durability_desc, is_cdc_enabled
FROM sys.databases
WHERE name = N'SalesDB';

-- 2016-2022: tables without a primary key cannot be mirrored
SELECT s.name AS SchemaName, t.name AS TableName
FROM sys.tables t
JOIN sys.schemas s ON s.schema_id = t.schema_id
WHERE OBJECTPROPERTY(t.object_id, 'TableHasPrimaryKey') = 0
ORDER BY 1, 2;

For SQL Server 2016-2022, also check that SQL Server Agent is running and set to start automatically, because CDC capture and cleanup run as Agent jobs:

Get-Service -Name SQLSERVERAGENT, 'SQLAgent$*' -ErrorAction SilentlyContinue |
    Select-Object Name, Status, StartType

Step 2: Install a data gateway

If the SQL Server isn't reachable from the internet, which is the usual case on-premises, Fabric connects through a data gateway:

  • On-premises data gateway: install it on a Windows server that can reach SQL Server on port 1433 (or your port) and has outbound HTTPS to Azure.
  • Virtual network data gateway: use it when SQL Server sits in an Azure VNet.

Register the gateway to the same tenant as the Fabric workspace. Then test the connection from the gateway machine:

Test-NetConnection -ComputerName sql01.corp.local -Port 1433

Tip

Install a second gateway member in the same cluster. If the only gateway goes down, mirroring stops.

Step 3: Create the login Fabric uses

SQL Server 2016-2022

Fabric needs sysadmin only while it enables CDC. Remove it afterwards.

USE [master];
CREATE LOGIN [fabric_login] WITH PASSWORD = '<strong password>';
GRANT CONNECT SQL TO [fabric_login];
ALTER SERVER ROLE [sysadmin] ADD MEMBER [fabric_login];
GO
USE [SalesDB];
CREATE USER [fabric_user] FOR LOGIN [fabric_login];
GRANT CONNECT, SELECT TO [fabric_user];

After mirroring is running (Step 5), drop the elevated role:

USE [master];
ALTER SERVER ROLE [sysadmin] DROP MEMBER [fabric_login];

Later CDC maintenance, such as re-enabling a table after a schema change, needs sysadmin again.

SQL Server 2025

  1. Connect the server to Azure Arc. This installs the Azure extension for SQL Server.
  2. Turn on the managed identity for the Arc-enabled SQL Server.
  3. Check that the identity exists:
SELECT * FROM sys.dm_server_managed_identities;  -- expect one System-assigned row
  1. Create a least-privilege login. Sysadmin isn't needed:
USE [master];
CREATE LOGIN [fabric_login] WITH PASSWORD = '<strong password>';
GO
USE [SalesDB];
CREATE USER [fabric_user] FOR LOGIN [fabric_login];
GRANT SELECT, ALTER ANY EXTERNAL MIRROR,
      VIEW DATABASE PERFORMANCE STATE, VIEW DATABASE SECURITY STATE
   TO [fabric_user];

For an Always On availability group, create the login on every replica and connect every node to Arc.

Step 4: Create the mirrored database in Fabric

  1. In the Fabric portal, open the workspace and select Create, then Mirrored SQL Server database. Give it a name.
  2. Under New sources, choose SQL Server database and fill in:
    • Server: the fully qualified name, or the AG listener for an availability group.
    • Database: SalesDB.
    • Data gateway: the gateway from Step 2.
    • Authentication: fabric_login and its password.
  3. Select Connect.
  4. On Configure mirroring, keep Mirror all data to include tables created later as well. Clear it to choose specific tables.
  5. Select Create mirrored database. After 2-5 minutes, open Monitor replication.

Each table should show Running, and Last refresh fills in once the initial snapshot is complete.

Step 5: Check that replication is healthy

In Fabric, the Monitor replication page shows the status, rows replicated and last refresh time for each table. On the source, check the capture side.

SQL Server 2016-2022 (CDC):

USE [SalesDB];

-- Tables Fabric enabled for CDC
SELECT s.name AS SchemaName, t.name AS TableName, t.is_tracked_by_cdc
FROM sys.tables t JOIN sys.schemas s ON s.schema_id = t.schema_id
WHERE t.is_tracked_by_cdc = 1;

-- Capture job activity and latency (seconds)
SELECT TOP (10) start_time, end_time, tran_count, latency
FROM sys.dm_cdc_log_scan_sessions
ORDER BY start_time DESC;

-- Recent capture errors
SELECT * FROM sys.dm_cdc_errors;

SQL Server 2025 (change feed):

SELECT TOP (10) * FROM sys.dm_change_feed_log_scan_sessions ORDER BY start_time DESC;
SELECT * FROM sys.dm_change_feed_errors;

Check that the log isn't growing because capture can't keep up:

SELECT name, log_reuse_wait_desc FROM sys.databases WHERE name = N'SalesDB';

A log_reuse_wait_desc that stays at REPLICATION means log records are waiting for capture. Find out why: check whether the Agent job is stopped (2016-2022), whether mirroring is stopped, or whether the capacity is paused.

Caution

If you stop mirroring in Fabric for a long time while the source keeps changing, the transaction log can fill the disk. Watch log size and log_reuse_wait_desc during any pause, and stop mirroring cleanly if it won't restart soon.

Step 6: Plan for the limits

Area Limit What to do
Tables Up to 1,000 tables per mirrored database Split across several mirrored databases or mirror only reporting tables
Primary keys (2016-2022) Tables without a primary key are skipped Add a primary key, or load those tables with a pipeline
Data types xml, geometry, geography, hierarchyid, sql_variant, timestamp, json, vector, UDTs and computed columns aren't replicated Expose them as plain columns in another table, or skip them
Precision datetime2(7), time(7) and datetimeoffset(7) keep 6 digits in Delta Fine for most reporting; note it for audit data
LOB columns Values over 1 MB are truncated to 1 MB Keep large documents out of the mirror
Schema changes (2016-2022) A DDL change on a mirrored table fails with "definition has changed since CDC was enabled" Disable and re-enable CDC on that table; it reseeds
Schema changes (2025) The changed table is re-snapshotted automatically Schedule large DDL out of hours
HA Only the AG primary is supported; failover cluster instances are not Connect through the listener
Security Row-level security, column permissions and masking don't carry over to OneLake Re-apply security in Fabric
Restart Stopping and starting mirroring reseeds every table Avoid stop/start on large databases

Fix a 2016-2022 table after a schema change (needs sysadmin or db_owner):

EXEC sys.sp_cdc_disable_table @source_schema = N'dbo', @source_name = N'Orders',
     @capture_instance = N'all';
EXEC sys.sp_cdc_enable_table  @source_schema = N'dbo', @source_name = N'Orders',
     @role_name = NULL, @supports_net_changes = 1;

For an availability group on 2016-2022, the CDC capture and cleanup jobs must exist on every replica and run only on the primary. After each failover, enable them on the new primary.

Step 7: Use the data

Each mirrored database comes with a SQL analytics endpoint. Query it from SSMS or the Fabric query editor with the connection string shown in the workspace:

SELECT TOP (100) OrderID, CustomerID, OrderDate, TotalDue
FROM dbo.Orders
ORDER BY OrderDate DESC;

To use the data in a Lakehouse or notebook, create OneLake shortcuts to the mirrored tables instead of copying them. Power BI semantic models can use Direct Lake over the same Delta tables.

Quick checklist

  • Capacity active; workspace Admin or Member; tenant settings on
  • Gateway installed (two members) and can reach SQL Server
  • Delayed durability off; primary keys present (2016-2022); CDC off (2025)
  • Agent running (2016-2022) or Arc and managed identity set up (2025)
  • Login created; sysadmin removed after setup (2016-2022)
  • Mirror created; all tables Running; Last refresh filled in
  • Monitoring of capture errors and log_reuse_wait_desc in place
  • Security re-applied in Fabric

Further reading