Skip to content

SQL Server

SQL Server as a source

Setting it up: SQL Server.

"Could not open a connection to SQL Server"

The agent, or the Replicator Service's ODBC connection, can't reach SQL Server.

What to do: in SQL Server Configuration Manager, on the SQL Server computer:

  1. Check that the TCP/IP protocol is enabled for the instance (see Open the network).
  2. In the TCP/IP protocol's properties, check that the addresses on the IP Addresses tab are right, especially after the server's IP address changed (for example with DHCP).
  3. For a named instance, or several instances on the computer, check that the SQL Server Browser service is running, unless you connect with the instance's port.

Then check the firewall and the ports.

"Could not create a capture instance because the capture instance name 'schema_table' already exists"

With Change Data Capture, adding a subscription, or starting its baseline, fails with an error such as:

Failed to add incremental subscription at Capture Agent for source table 'dbo.MYTABLE'. Snapshot could not be
started. ... Failed to add subscription: Could not create a capture instance because the capture instance name
'dbo_MYTABLE' already exists in the current database. Specify an explicit unique name for the parameter
@capture_instance. SQLSTATE=S0001

It usually happens after a table was dropped and re-created, or renamed, at the source. The same table may still replicate in another group.

Cause: when a subscribed table has no capture instance, the agent turns on Change Data Capture for it with SQL Server's default capture instance name, schema_table. A capture instance with that name already exists but belongs to another table, for example one left from the table's earlier version or from a renamed table. manageMsCdcCapture (see Settings) doesn't help: the agent manages only the capture instances of the table itself.

What to do: turn on Change Data Capture for the table yourself, with a capture instance name that isn't used yet. The agent then uses that capture instance.

  1. Delete the failing subscription.
  2. In the source database, list the existing capture instances and their tables:

    SELECT capture_instance, OBJECT_NAME(source_object_id) AS source_table FROM cdc.change_tables;
    EXEC sys.sp_cdc_help_change_data_capture;
    
  3. Pause the source, and stop the agent.

  4. Turn on Change Data Capture for the table with a new, unique capture instance name, for example dbo_MYTABLE_2:

    USE mydb;
    EXEC sys.sp_cdc_enable_table @source_schema = N'dbo', @source_name = N'MYTABLE',
         @role_name = NULL, @supports_net_changes = 0, @capture_instance = N'dbo_MYTABLE_2';
    
  5. Start the agent and resume the source.

  6. Create the subscription again and run its baseline.

When an application drops and re-creates a replicated table, check its capture instances afterwards.

The subscription wizard lists the tables of another database

The SQDR source points at a second database on the same SQL Server, but the subscription wizard lists the tables of the database the agent captures.

Cause: an agent captures one database, and the source uses the agent named by its Capture Agent Schema.

What to do: add a Capture Agent for the second database (see Add the Capture Agent) and start it. Then, in the source's Incremental Replication properties, choose that agent's control schema (database.schema) as Capture Agent Schema, or create a new source for it. Changing the Capture Agent Schema of a source that already has incremental groups resets them, so a new source is usually better.

Changes stop arriving and the group stays in Synchronizing the baseline(s)

With Change Data Capture, the incremental group stays in Synchronizing the baseline(s) and no new changes arrive.

Cause: the SQL Server Agent service isn't running, so CDC's capture job doesn't fill the change tables.

What to do: start the SQL Server Agent service on the source and set it to start automatically (see Set up Change Data Capture). EXEC sys.sp_cdc_help_jobs; lists the capture and cleanup jobs.

"Change Data Capture is disabled for table"

Changes to a table stop arriving. In the Data Replicator Manager, the group and the subscription show a warning, with the message "Source table was altered. Use the Merge with Source function in the subscription properties to automatically update column information." The agent's Diagnostics tab shows:

MsSqlCdcChangePropagator.tableAltered: Change Data Capture is disabled for dbo.MYTABLE
...
Subscription.subscriptionFailed:MYTABLE

Cause: Change Data Capture was turned off for the table at the source, for example with sys.sp_cdc_disable_table.

What to do: open the subscription's properties and click OK. The subscription is created again: the agent turns Change Data Capture on for the table again, and a new baseline runs.

"Invalid object name 'cdc.lsn_time_mapping'"

Changes stop arriving, but the Data Replicator Manager shows no error. In the SQDR Control Center, the agent shows a warning, and its Diagnostics tab shows:

MsSqlCdcLogReader.next: com.microsoft.sqlserver.jdbc.SQLServerException: Invalid object name 'cdc.lsn_time_mapping'.

In SQL Server Management Studio, the subscribed tables show Table is replicated as False.

Cause: Change Data Capture was turned off for the whole database (sys.sp_cdc_disable_db). cdc.lsn_time_mapping is a system table that exists only while CDC is on for the database.

What to do:

  1. Turn CDC on again for the database: EXEC sys.sp_cdc_enable_db;. Until the agent restarts, its diagnostics then show "Invalid journaling/logging options: Change Data Capture is not active. Is the SQL Server Agent running?".
  2. Stop the agent, set its startup mode to Warm (restored) (see Startup mode), and start it. It turns CDC on again for the subscribed tables. Right after the start, "Connection refused to host: 127.0.0.1" messages in the diagnostics, and a "returned error 11 ... Connection refused" message in the Data Replicator Manager, are expected and pass.
  3. Unless you're sure the source tables didn't change while CDC was off, run new baselines for the subscriptions: changes made in that time weren't captured.

"Snapshot could not be started ... SQLCODE=-206"

Adding an incremental subscription fails with a message such as:

Failed to add incremental subscription at Capture Agent for source table 'dbo.MYTABLE'. Snapshot could not be
started. Error: Stored procedure SQDR.ADDSUBSCRIPTION ... returned error 11. ... Failed to add subscription: DB2 SQL
Error: SQLCODE=-206, SQLSTATE=42703, SQLERRMC=MYCOLUMN

Cause: Quote SQL identifiers was off when the subscription was created. SQL Server subscriptions need it.

What to do: turn on Quote SQL identifiers (see Replication defaults), then delete the subscription and create it again.

"Database 'name' is being recovered. Waiting until recovery is finished."

The database has the AUTO_CLOSE option on: see Turn off AUTO_CLOSE and AUTO_CLOSE.

Other messages

For any other message, see Error messages.

SSL/TLS connections to a SQL Server source

Setting it up: SSL/TLS connections to a SQL Server source.

SQL Server doesn't start: "error code: 0x8009030D"

The SQL Server service fails to start after you select the certificate, and its error log says:

A fatal error occurred when attempting to access the SSL server credential private key.
Error code: 0x8009030D. Internal error state: 10001.

Cause: the account the SQL Server service logs on as can't read the certificate's private key.

What to do: grant that account Read permission on the private key (see Grant the SQL Server service account read access to the private key), then start the service.

"SSL Provider: The target principal name is incorrect"

An ODBC connection (the SQDR source or destination, or Test Data Source) fails with [Microsoft][ODBC Driver 17 for SQL Server]SSL Provider: The target principal name is incorrect.

Cause: the server name in the connection doesn't match the name in the certificate.

What to do: connect with the fully qualified name in the certificate, for example myhost.mydomain.com\SQLEXPRESS, not localhost, a short name or an IP address (see Configure SQDR's ODBC data source or connection string).

"The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption"

The agent's Diagnostics tab shows com.microsoft.sqlserver.jdbc.SQLServerException: The driver could not establish a secure connection to SQL Server by using Secure Sockets Layer (SSL) encryption.

Cause: Stelo Capture doesn't trust the certificate authority that issued the SQL Server's certificate.

What to do: add the certificate authority's certificate on the Certificates tab (see Add the CA certificate on the Certificates tab), and check that the agent's Host Name is the fully qualified name in the certificate.

"The certificate received from the remote server has either expired or is not yet valid"

Cause: the SQL Server's certificate has expired, or its validity period hasn't started yet.

What to do: renew or replace the certificate on the server (see Install a certificate on the server with MMC), select it again in SQL Server Configuration Manager if it's a new certificate, and restart the SQL Server service.

SQL Server as a destination

Setting it up: SQL Server.

"Could not open a connection to SQL Server"

The connection to SQL Server fails with this message. Check the instance's network settings as for a source (see "Could not open a connection to SQL Server"), and Network.

"The server principal "user" is not able to access the database "name" under the current security context" after a restore

After a destination database was restored from a backup (.bak) of another, identically set-up server, replication fails with this message from the SQL Server ODBC driver. It can happen the same way for a source or a SQL Server control database (for the Replicator Service's own account, see SQDRSVC error 1010 or 2012).

Cause: the user in the restored database is no longer mapped to the server's login of the same name: their security identifiers (SIDs) differ.

What to do:

  1. Check that the login exists on the instance (Security › Logins in SQL Server Management Studio).
  2. In a query window, map the database user to the login again (replace MYDB and sqdruser):

    USE MYDB;
    ALTER USER sqdruser WITH LOGIN = sqdruser;
    

To compare the SIDs, check the sid column of SELECT name, sid FROM sys.server_principals WHERE name = 'sqdruser'; (in master) and of SELECT name, sid FROM sys.database_principals WHERE name = 'sqdruser'; (in the database).

Certificate errors after moving to Driver 18

Driver 18 encrypts and checks the server's certificate by default: see Move to ODBC Driver 18.

"The insert thread timed out waiting for a filled fetch buffer"

A subscription fails with "Replication failed. The insert thread timed out waiting for a filled fetch buffer."

Cause: the destination SQL Server waited for a resource (for example a lock or I/O) for longer than the Multithread timeout, 30 seconds by default. The message can occur with any destination.

What to do: raise Multithread timeout (seconds), for example to 300, for the Replicator Service (the rowBufferTimeout property) or for the group (see Group properties). If the destination is slow, see Slow apply to SQL Server.

"Bulk-copy commit failed (bcp_batch)" with text or image columns

With bulk copy (Use native-loader function, if available), a text or image column that holds NULL or zero-length values can make the copy fail with a message such as:

Bulk-copy commit failed (bcp_batch). ODBC message: SQLSTATE 37000, native error 4813, [Microsoft][ODBC SQL Server
Driver][SQL Server]Expected the text length in data stream for bulk copy of text, ntext, or image data.

or copy fewer rows than expected, depending on the driver. SQDR creates these types only with Enable deprecated types (see Data types). Work around it in one of these ways:

  • Choose Insert using ODBC in the subscription's Baseline Replication Options.
  • Move the text or image column to the first position on the Columns tab. This works only if the table has one such column with NULL or empty values.
  • Leave out the rows with NULL values with a criteria, for example MYTEXTCOL IS NOT NULL.

"Error loading library rpsqls28.dll"

With the SQDR bundled SQL Server driver, a subscription fails with "Error loading library rpsqls28.dll" (or rpsqls27.dll). This driver has no bulk copy: choose Insert using ODBC instead of Use native-loader function, if available in the subscription's Baseline Replication Options (see SQDR bundled SQL Server driver).

"Attempt to use Bulk Copy with a non-existent Server table"

A subscription that loads with SQL Server Bulk Copy fails with this message.

Cause: the name SQL Server has for itself doesn't match the computer's name, typically after the computer was renamed.

What to do: on the destination SQL Server:

  1. Compare SELECT @@SERVERNAME with the computer's name (for a named instance, computer\instance).
  2. If they differ, replace the old name with the current one:

    EXEC sp_dropserver 'OLDNAME';
    EXEC sp_addserver 'NEWNAME', 'local';
    
  3. Restart the SQL Server service, and check SELECT @@SERVERNAME again.

Slow apply to SQL Server

Replication to a SQL Server destination becomes slow: the SQDR Control Center shows a growing backlog of changes for the Capture Agent, and the Data Replicator Manager shows the changes being applied, but slowly, while every SQDR component looks healthy. Look at the destination SQL Server:

  1. Resources. Check CPU and memory use on the destination server.
  2. Locks. Check that nothing else locks the destination tables. Turn on snapshot isolation and read committed snapshot (see Snapshot isolation).
  3. Expensive statements. In SQL Server Management Studio's Activity Monitor, under Active Expensive Queries or Recent Expensive Queries, look for SQDR's statements after a few minutes (for example an UPDATE of a destination table; they're easiest to find when SQDR has a login of its own). A statement's execution plan shows what could be improved, for example with an index.
  4. Blocked or waiting sessions. If no SQDR statement shows up, open Processes in Activity Monitor and look for SQDR's sessions that are blocked by another session (a value in Blocked By: another session holds a lock on the table), or in the wait type TRACEWAIT, which a running trace or exhausted resources (for example buffers) can cause: end the trace, or restart SQL Server or the server. sp_who and sp_who2, or the free community procedure sp_WhoIsActive, show the same sessions from a query window.
  5. Throughput. In the Data Replicator Manager, run the IR_SubscriptionStats.sql report with Query: its RPS column shows rows per second. To see the current rate rather than the history, click Delete Statistics for the group, wait a while, and run the report again. Compare it with the rate you saw before, and again after a fix.
  6. Always On availability groups. With synchronous commit, every commit waits for the secondary replicas, which shows as long pauses in applying changes, or a long delay after a baseline, and as sessions in the wait type HADR_SYNC_COMMIT. Consider asynchronous commit, a faster network between the replicas, faster replica servers, or fewer indexes on the destination tables.
  7. Azure SQL Database and Azure SQL Managed Instance. The service throttles I/O when the database exceeds its provisioned limits. sys.resource_stats (CPU and storage, in five-minute intervals, kept 14 days), sys.dm_db_resource_stats (CPU, I/O and memory, every 15 seconds, kept one hour) and sys.dm_db_wait_stats (the waits) show whether it does. See Microsoft: Azure SQL Managed Instance resource limits.

Other problems

See also: