How to fix Error 2628 on Windows Server 2025 / Windows 11

Troubleshooting Guide: Error 2628 – “String or Binary Data Would Be Truncated”

Why This Error Happens

This error occurs when an INSERT or UPDATE statement attempts to insert data into a column that exceeds the defined length or precision of that column’s data type (e.g., inserting 60 characters into a VARCHAR(50) field). Unlike older versions of SQL Server, SQL Server 2025 provides the exact column name, row details, and truncated value directly in the error message, making it easier to isolate the offending data. This typically stems from mismatched application-to-database schema assumptions, bulk import files with inconsistent field widths, or recent schema changes that reduced column size without updating upstream validation logic.

Step-by-Step Resolution Guide

Step 1: Identify the Exact Column and Offending Value

  • Read the full error message text; SQL Server 2025 now explicitly names the table, column, and the actual value/row causing the truncation.
  • Run the query manually in SQL Server Management Studio (SSMS) with SET ANSI_WARNINGS ON; to reproduce the detailed error context.
  • Cross-reference the column definition using:
  SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH 
  FROM INFORMATION_SCHEMA.COLUMNS 
  WHERE TABLE_NAME = 'YourTableName';

Step 2: Correct the Data or Expand the Column Definition

  • If the data itself is invalid (e.g., accidental concatenation or bad import mapping), fix the source data file or ETL mapping logic.
  • If the business requirement now requires longer strings, alter the table schema:
  ALTER TABLE YourTableName 
  ALTER COLUMN YourColumnName VARCHAR(100);
  • Ensure you check dependent Views, Stored Procedures, or Indexed columns before altering size, as this can trigger a schema lock.

Step 3: Audit Application and Import Layer Validation

  • Open your application’s data access layer (e.g., Entity Framework, ADO.NET, or SSIS packages) and verify the input validation matches the updated SQL schema length.
  • For SSIS/Bulk Import jobs, open the Advanced Editor on the Flat File Source and update the OutputColumnWidth property to match the new SQL column constraints.
  • Restart the SQL Server Agent service via services.msc on Windows Server 2025 if a scheduled job was caching an old execution plan.

Step 4: Implement Pre-Validation Logic (Optional Hardening)

  • Add a TRY_CONVERT or LEN() check in your stored procedures to proactively reject oversized strings before they hit the insert command, returning a custom friendly error instead of Error 2628.

Alternative or Verification Steps

  • Verify the Fix: Re-run the original INSERT/UPDATE transaction or trigger the specific ETL package again; confirm the transaction commits without rollback.
  • Alternative Fix: If altering the table schema is restricted by compliance policies, use LEFT(YourVariable, 50) within the application code to safely truncate the string before it reaches the database layer, preventing the hard error (though this risks silent data loss).