---
title: "CDC Sink for SQL Server: Overview"
description: "CDC Sink support for SQL Server - using native SQL Server Change Data Capture to stream changes into RavenDB."
url: "https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/sql-server/overview"
version: "7.2"
language: "csharp"
---

# CDC Sink for SQL Server: Overview

> Client language: C#.
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

> **Note**
>
> - CDC Sink supports **SQL Server** as a source database using native
>   [SQL Server Change Data Capture](https://learn.microsoft.com/en-us/sql/relational-databases/track-changes/about-change-data-capture-sql-server).
>
> - SQL Server CDC captures row-level changes from the transaction log and stores them in CDC change tables.  
>   The CDC Sink task polls SQL Server CDC for new changes and applies INSERTs, UPDATEs, and DELETEs  
>   to RavenDB documents.
>
> - In this article:
>   - [Connection string](#connection-string)
>   - [Prerequisites](#prerequisites)
>   - [Table verification](#table-verification)
>   - [Polling behavior](#polling-behavior)
>   - [Task configuration](#task-configuration)

## Connection string {#connection-string}

Use a [SqlConnectionString](https://docs.ravendb.net/7.2/server/ongoing-tasks/etl/sql.md#add-an-sql-connection-string) with `FactoryName` set to `"Microsoft.Data.SqlClient"`:

### Sync

```csharp
store.Maintenance.Send(new PutConnectionStringOperation<SqlConnectionString>(
    new SqlConnectionString
    {
        Name = "SqlServerConnection",
        FactoryName = "Microsoft.Data.SqlClient",
        ConnectionString =
            "Server=myserver;Database=mydb;" +
            "User Id=ravendb_cdc;Password=...;" +
            "TrustServerCertificate=True;"
    }));
```

### Async

```csharp
await store.Maintenance.SendAsync(new PutConnectionStringOperation<SqlConnectionString>(
    new SqlConnectionString
    {
        Name = "SqlServerConnection",
        FactoryName = "Microsoft.Data.SqlClient",
        ConnectionString =
            "Server=myserver;Database=mydb;" +
            "User Id=ravendb_cdc;Password=...;" +
            "TrustServerCertificate=True;"
    }));
```

> **Warning**
>
> `Microsoft.Data.SqlClient` defaults to `Encrypt=True`.  
> Unless SQL Server presents a certificate trusted by the RavenDB server, add `TrustServerCertificate=True`  
> (as above) or `Encrypt=False` to the connection string. Otherwise, the CDC Sink task cannot connect.

## Prerequisites {#prerequisites}

Before CDC Sink can capture changes,  
SQL Server CDC must be enabled on the source database and on every source table configured in the task.

If the SQL Server user in the CDC Sink connection string has permission to enable CDC,  
RavenDB enables it automatically when the task starts. Otherwise, ask a database administrator to run:

```sql
-- Enable CDC on the database
EXEC sys.sp_cdc_enable_db;

-- Enable CDC on a table
EXEC sys.sp_cdc_enable_table
    @source_schema = N'dbo',
    @source_name = N'orders',
    @role_name = NULL;
```

The SQL Server Agent service must be running for CDC change capture to work.  
The Agent runs the capture jobs that populate the change tables.

On-premises, start the SQL Server Agent service; in Docker containers, start with `-e 'MSSQL_AGENT_ENABLED=true'`.  
If the Agent is stopped, the task can still start and raise a warning, but no CDC changes are delivered until the Agent is running.

> **Note**
>
> #### Azure SQL Database
>
> Azure SQL Database has no classic SQL Server Agent.  
> Its CDC capture runs on a managed scheduler, so this requirement does not apply there.

## Table verification {#table-verification}

**Verify tables** in Studio, or the [dry-run REST endpoint](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/create-task.md#verify-the-configuration), runs the task's SQL Server setup and initial-load steps once  
against the source database before you save the task,
see [Verify tables](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/create-task.md#verify-tables).

- **CDC is enabled temporarily**  
  If CDC is not enabled on the database or on a configured table,  
  verification enables it with `sys.sp_cdc_enable_db` or `sys.sp_cdc_enable_table`, as the task does when it starts.  
  The user in the connection string needs permission to run these procedures.  
  Otherwise, verification fails with the script an administrator can run.

- **Cleanup after verification**  
  If verification enabled CDC on the database, it attempts to run `sys.sp_cdc_disable_db`.  
  Otherwise, it attempts to run `sys.sp_cdc_disable_table` for each table it enabled.  
  If this cleanup fails, verification reports a warning,
  see [Table verification fails or returns warnings](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/troubleshooting.md#table-verification-fails-or-returns-warnings).

- **SQL Server Agent is not checked**  
  The task checks the Agent only when it starts polling for changes,  
  so a successful verification does not mean the Agent is running.

> **Note**
>
> `sys.sp_cdc_disable_db` removes every capture instance in the database.  
> If another CDC Sink task enables CDC on the same database while verification is running,  
> the capture instances that task created are removed as well.

## Polling behavior {#polling-behavior}

Unlike PostgreSQL and MySQL, SQL Server CDC Sink uses polling rather than a streaming replication connection.  
The `CdcSink.SqlServer.PollIntervalInSec` server configuration key controls how frequently the task polls for new change rows.

Lower values reduce latency, but increase load on the source database.  
See [Server Configuration](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/server-configuration.md).

## Task configuration {#task-configuration}

SQL Server CDC Sink uses the same `CdcSinkConfiguration` table, mapping, patching, and delete-handling settings as the other source engines.
SQL Server does not use the PostgreSQL-specific `Postgres` settings.

See [Configuration Reference](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/configuration-reference.md)
for full details.

When `SourceTableSchema` is omitted, SQL Server uses `"dbo"` as the default schema.

## See also

- [Overview](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/overview.md)
- [Configuration Reference](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/manage-cdc-sink-tasks/configuration-reference.md)
- [PostgreSQL Prerequisites Checklist](https://docs.ravendb.net/7.2/server/ongoing-tasks/cdc-sink/source-database-setup/postgres/prerequisites-checklist.md)
