Troubleshooting Guide: SQL Server Error 2354 – Invalid Source Character Encoding
Why This Error Happens
This error typically occurs when SQL Server 2025 encounters a data import or ETL operation where the source file’s character encoding does not match the encoding expected by the destination collation settings. It is commonly triggered by BCP, BULK INSERT, or SSIS operations reading flat files saved in an unsupported or mismatched format (such as UTF-8 without a BOM, or extended ASCII) when the server expects UTF-16 or a specific code page. Corrupted or truncated source files can also trigger this error even when encoding settings are technically correct.
Step-by-Step Resolution Guide
Step 1: Verify the Source File Encoding
- Open the source file in a text editor like VS Code or Notepad++ and check the encoding indicator in the status bar.
- Confirm whether the file is saved as UTF-8, UTF-8-BOM, UTF-16 LE, or ANSI.
- Run
file -i sourcefile.csvif using WSL or a Linux-based utility to cross-check encoding metadata.
Step 2: Align the Format File or Import Statement with the Correct Encoding
- If using BULK INSERT or BCP, explicitly declare the
CODEPAGEparameter in your T-SQL command (e.g.,CODEPAGE = '65001'for UTF-8). - For BCP operations, regenerate the format file using
bcp dbo.TableName format nul -c -t, -f C:\Formats\table.fmt -U sa -P password -S ServerName. - Ensure the
DATAFILETYPEparameter matches the actual file type (char,native,widechar, orwidenative).
Step 3: Re-Save or Convert the Source File
- Use PowerShell to force a clean re-encoding pass:
Get-Content C:\Data\source.csv | Set-Content -Encoding UTF8 C:\Data\source_fixed.csv. - If the file originated from a non-Windows system, strip any stray BOM characters using a hex editor to confirm no leading byte-order-mark artifacts remain.
- Re-attempt the import process against the newly saved file.
Step 4: Check Database and Column-Level Collation Settings
- Navigate to SQL Server Management Studio (SSMS) and right-click the target database > Properties > Options to confirm the default collation.
- Run
SELECT name, collation_name FROM sys.columns WHERE object_id = OBJECT_ID('dbo.TableName');to verify no column-level collation conflicts exist. - Adjust collation to a Unicode-compatible setting (e.g.,
Latin1_General_100_CI_AS_SC_UTF8) if cross-language characters are involved.
Alternative or Verification Steps
- After re-running the import, query the affected table with
SELECT TOP 100 * FROM dbo.TableName WHERE Column1 LIKE '%?%';to check for unexpected replacement characters indicating lingering encoding mismatches. - If the error persists, bypass BCP/BULK INSERT entirely and import the dataset through SSIS using a Flat File Source component, manually setting the “Code Page” property in the Connection Manager to match the verified source encoding from Step 1.