Skip to main content

CDC for Microsoft SQL Server

Microsoft SQL Server CDC integrations capture row-level changes from SQL Server tables in real time using Debezium-based Change Data Capture. Use them for data synchronization, audit logging, and event-driven workflows that must react to database inserts, updates, and deletes without polling.

note

CDC must be enabled on the SQL Server database and on the specific tables you want to track before creating this integration. See Prerequisites.

Prerequisites

Before creating the integration:

  • SQL Server Agent must be running. CDC relies on Agent jobs to copy changes from the transaction log into change tables. If the agent isn't running, no change events are published. Verify by running EXEC master.dbo.xp_servicecontrol N'QueryState', N'SQLServerAGENT'; and confirming the returned state indicates the service is running.
  • Enable CDC on the target database and on each table you want to track.
-- Enable CDC on the database
EXEC sys.sp_cdc_enable_db;

-- Enable CDC on a specific table
EXEC sys.sp_cdc_enable_table
@source_schema = N'dbo',
@source_name = N'customers',
@role_name = NULL,
@supports_net_changes = 1;

Enabling CDC on a table creates a change table at cdc.<capture_instance>_CT, where capture_instance defaults to <schema>_<table> unless overridden with the @capture_instance parameter. The Debezium connector reads from this change table. For advanced Debezium properties, see the Debezium connector for SQL Server.

Create a CDC service for Microsoft SQL Server

  1. Click + Add Artifact in the canvas or click + next to Entry Points in the sidebar.

  2. In the Artifacts panel, select CDC for Microsoft SQL Server under Event Integration.

  3. In the creation form, select Create new to configure a new listener.

    Microsoft SQL Server CDC creation form: connection fields

    Under Listener Configurations, fill in the following fields:

    FieldDescriptionDefault
    HostHostname of the Microsoft SQL Server.localhost
    PortPort number of the Microsoft SQL Server.1433
    UsernameUsername for the SQL Server connection.Required
    PasswordPassword for the SQL Server connection.Required
    DatabasesList of databases to capture changes from. Click + Add Item to add each database name.Required
    SchemasRegular expressions matching schema names to capture changes from. Click + Add Item to add each pattern.

    Expand Advanced Configurations for additional settings:

    FieldDescriptionDefault
    Listener NameIdentifier for the listener created with this service.mssqlCdcListener
    Database InstanceMicrosoft SQL Server named instance (if applicable).
    Secure SocketSSL/TLS configuration for a secure connection.
    OptionsAdditional options for the CDC engine as a record expression. Common keys include snapshotMode (for example, "no_data" to skip the initial snapshot) and skippedOperations (for example, [cdc:TRUNCATE, cdc:UPDATE, cdc:DELETE] to capture only inserts).

    Under Table, enter the fully qualified table name to capture events from in the format <database>.<schema>.<table> (for example, mydb.dbo.customers).

  4. Click Create.

  5. WSO2 Integrator opens the service in the Service Designer. The canvas shows the attached listener pill and the table name pill.

    Service Designer showing the Microsoft SQL Server CDC service canvas

  6. Click + Add Handler to add event handlers.

Service configuration

In the Service Designer, click the Configure icon in the header to open the CDC for Microsoft SQL Server Configuration panel. Select CDC for Microsoft SQL Server in the left panel.

Microsoft SQL Server CDC Configuration panel: service config and listener connection

FieldDescription
Service ConfigAdvanced CDC configuration as a record expression. The tables field sets the fully qualified table name (format: <database>.<schema>.<table>).

Listener configuration

In the CDC for Microsoft SQL Server Configuration panel, select mssqlCdcListener under Attached Listeners to configure the listener.

Listener configuration: Database, Engine Name, Internal Schema Storage, Offset Storage, Liveness Interval, Options

FieldDescriptionDefault
NameIdentifier for the listener.mssqlCdcListener
DatabaseDatabase connection configuration as a record expression with hostname, port, username, password, and databaseNames fields.Required
Engine NameDebezium engine instance name.ballerina-cdc-connector
Internal Schema StorageSchema history storage configuration.{fileName: "tmp/dbhistory.dat"}
Offset StorageOffset storage configuration for tracking CDC progress.{fileName: "tmp/debezium-offsets.dat"}
Liveness IntervalInterval in seconds for checking CDC listener liveness.60.0
OptionsAdditional connector options as a record expression.{}

Click + Attach Listener to attach an additional listener to the same service.

Click Save Changes to apply updates.

Polling interval

The Debezium SQL Server connector reads changes from CDC change tables on a polling cycle. To tune the cycle, set Debezium properties such as poll.interval.ms in the Options field (for example, { "poll.interval.ms": "1000" }).

Event handlers

Adding an event handler

In the Service Designer, click + Add Handler. The Select Handler to Add panel lists onRead, onCreate, onUpdate, onDelete, and onError.

onRead, onCreate, onUpdate, and onDelete each open a configuration panel with a + Define Database Entry option to define the expected record type for the change event. Click Save to add the handler.

onError is added directly without additional configuration.

Added handlers appear in the Event Handlers list on the Service Designer, where you can edit or remove each one.

Service Designer for a CDC for Microsoft SQL Server service showing the Event Handlers list with onCreate, onUpdate, onDelete, and onError entries.

Handler types

HandlerTriggered whenUse when
onReadA row is read during the initial snapshot of the tableBootstrapping downstream systems with existing data
onCreateA row is inserted into the tracked tableSyncing new records to downstream systems
onUpdateA row is updated in the tracked tablePropagating field changes
onDeleteA row is deleted from the tracked tableRemoving records from downstream systems
onErrorA CDC processing error occursLogging failures and sending alerts

What's next

  • CDC for PostgreSQL — capture changes from PostgreSQL tables
  • Kafka — consume messages from Apache Kafka topics
  • Connections — reuse database credentials across services