Share via

SQL Agent Job failing with Error 8152 (String or binary data would be truncated) during Replication/Distribution

Ramya 0 Reputation points
2026-03-12T19:52:40.2633333+00:00

Hi everyone,

I am encountering a persistent failure in a SQL Server Agent Job that appears to be related to a Replication Distribution Agent.

The Error: The job fails at Step 1 (Distribution Agent startup) or Step 3 (Detect nonlogged agent shutdown) with the following error:

NT SERVICE\SQLSERVERAGENT. String or binary data would be truncated. [SQLSTATE 22001] (Error 8152). The step failed.

Environment:

  • SQL Server Version: [SQL Server 2022]
  • Context: This is occurring in a Replication environment (invoked by user XXXXX\XXXXX).

What I've checked:

The job history shows the generic 8152 error but does not specify which table or column is causing the truncation.

The "Detect nonlogged agent shutdown" message suggests the agent is crashing due to this data mismatch before it can log a specific detail.

Questions:

Is there a way to identify the specific transaction or column causing the truncation within the Distribution database?

  1. If I enable VERBOSE_TRUNCATION_WARNINGS (or Trace Flag 460), will the SQL Agent Job History capture the detailed column name?

Are there known issues where schema mismatches between Publisher and Subscriber trigger this specifically during the "Detect nonlogged agent shutdown" step?

Any guidance on how to pinpoint the offending column without re-initializing the entire subscription would be greatly appreciated.

SQL Server | Other
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Erland Sommarskog 133.2K Reputation points MVP Volunteer Moderator
    2026-03-12T22:11:33.0133333+00:00

    I have noticed that you don't always get information about column and value, but you only get the generic 8152. I have not noticed the exact pattern, but I know that there other situations than just writing to a column where you can get a truncation error, and Microsoft has not improved the error message for these situation.

    I would recommend that you set up an extended-events session that captures the event error_reported, and that you set up the event so that it captures the statement for the error. As it happens, I have an article for how to do this on my web site: Monitor Exceptions in Your Database. The article also includes a view to easily view the information. This should at least take you closer to a solution.

    0 comments No comments

  2. Q&A Assist
    2026-03-12T19:53:08.5833333+00:00
    AI generated content. This question contains an answer created with AI from Q&A Assist. Learn more

    Use the replication troubleshooting tools and logging around the Distribution Agent to locate the failing transaction and then inspect it in the distribution database; the generic 8152 error alone is not enough.

    1. Identify where replication is failing

    Follow the transactional replication troubleshooting flow:

    1. Use Replication Monitor to confirm that the error is occurring in the Distributor to Subscriber path (Distribution Agent).
    2. From Replication Monitor or SQL Server Agent → Job Activity Monitor, open the failing Distribution Agent job and review the job history for the exact step and error text.
    3. If the job history is not detailed enough, enable verbose logging for the Distribution Agent.

    Reference steps for this are in the transactional replication troubleshooter under “Troubleshooting methodology” and “Enable verbose logging on any agent.”

    1. Enable verbose logging for the Distribution Agent

    Verbose logging can capture the exact batch and command that fails at the Subscriber:

    1. Edit the Distribution Agent job step (the one that runs the agent executable).
    2. Add an -Output parameter and a verbosity level to the command line, for example:
      • -Output <path_to_log_file>
      • Ensure there is a space before -Output (the documentation explicitly calls out that a missing space can prevent startup).
    3. If the agent fails to start with a high verbosity level, decrease the verbosity by 1 as suggested in the troubleshooting guide.
    4. Restart the Distribution Agent job and let it fail again.
    5. Review the generated output file on disk; it will show the failed transaction and often the exact statement that caused the truncation.

    This is the primary supported way to see the failing statement when the job history only shows the generic 8152 error.

    1. Use the Distribution Agent error file

    The Distribution Agent supports an -ErrorFile argument:

    • -ErrorFile specifies a file that contains the failed replication transactions and associated error messages when failures occur at the Subscriber.
    • If not specified, an .err file with the agent name is generated in the current directory.

    Ensure the Distribution Agent is configured with -ErrorFile (or locate the default .err file) and inspect it for:

    • The failed batch (INSERT/UPDATE) being applied at the Subscriber.
    • The error message tied to that batch.

    This will give the exact T‑SQL statement and values that caused the truncation.

    1. Query MSrepl_errors in the distribution database

    The distribution database keeps extended error information in MSrepl_errors:

    SELECT TOP (100)
           time,
           source_name,
           error_code,
           error_text,
           xact_seqno,
           command_id
    FROM   distribution.dbo.MSrepl_errors
    ORDER BY time DESC;
    

    Key columns:

    • error_text – contains the error message (including 8152 text).
    • xact_seqno and command_id – identify the first transaction and command in the failed batch.

    Once the failing xact_seqno/command_id are known, use the standard replication metadata tables (e.g., commands in the distribution database) to locate the exact command and then map it back to the table and columns at the Subscriber. The documentation notes that MSrepl_errors is specifically for Distribution Agent and Merge Agent failure information.

    1. About VERBOSE_TRUNCATION_WARNINGS / Trace Flag 460

    The provided context does not document VERBOSE_TRUNCATION_WARNINGS or Trace Flag 460 behavior with SQL Agent job history, so no statement can be made from this context about whether they will surface column names in job history. The supported and documented way in this context to get more detail is:

    • Verbose agent logging (-Output with higher verbosity).
    • Distribution Agent -ErrorFile.
    • MSrepl_errors in the distribution database.
    1. Check for replication‑specific causes

    From the replication troubleshooting guidance:

    • Determine whether the error is in the Publisher to Distributor or Distributor to Subscriber path.
    • If it is in the Distribution Agent, the problem is with applying transactions at the Subscriber.

    Schema mismatches (for example, smaller column length at the Subscriber than at the Publisher) are a common cause of 8152 in replication scenarios, but the context here does not describe a specific “Detect nonlogged agent shutdown” bug or schema mismatch issue for SQL Server 2022. Use the methods above to identify the failing statement and then compare the table schema between Publisher and Subscriber for that table.

    1. General replication error‑handling steps

    If the agent continues to fail:

    1. Restart the agent and see if it runs without failures.
    2. Check agent history and job history for other errors around the same time.
    3. Verify connectivity between Publisher, Distributor, and Subscriber using the same accounts as the agents.
    4. If the error persists, increase logging and review the output file as described above.

    These steps are documented as the standard user actions for replication agent failures.


    References:

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.