Troubleshooting Guide: SQL Server Error 4899 – Invalid Terminator in CSV Format File
Why This Error Happens
This error occurs when the non-XML format file used for a CSV bulk load operation contains inconsistent column terminators across source columns. SQL Server 2025 enforces a strict CSV parsing rule: every source column terminator must be identical except for the final column, which must use a distinct row terminator (such as \r\n). This typically results from a manually edited or improperly auto-generated format file, or from exporting the format file using bcp with mismatched delimiter arguments.
Step-by-Step Resolution Guide
Step 1: Inspect the Format File Structure
- Open the
.fmtfile referenced in the error (the%spath) using a text editor like Notepad++ or VS Code on Windows Server 2025 / Windows 11. - Locate the
COLUMNdefinitions section and check theterminatorattribute for each field. - Confirm that all columns except the last use the exact same terminator string (e.g.,
","). - Verify the final column uses a row terminator like
"\r\n"instead of a comma.
Step 2: Regenerate the Format File Using bcp
- Open an elevated Command Prompt or PowerShell session.
- Run the following command to regenerate a clean format file:
bcp YourDatabase.dbo.YourTable format nul -c -t, -r "\r\n" -f C:\BulkData\YourTable.fmt -S YourServerName -T
- Ensure the
-tflag (field terminator) and-rflag (row terminator) match the actual structure of your CSV source file. - Avoid manually mixing terminators (e.g., semicolons for some columns and commas for others).
Step 3: Validate the CSV Source File Consistency
- Open the source CSV file in a plain text editor and confirm that every row uses the same delimiter throughout (no mixed commas/tabs/semicolons).
- Check for hidden or malformed characters near the last column, as trailing whitespace or stray delimiters can trigger this error.
- Save the file with UTF-8 or ANSI encoding depending on your
BULK INSERTorbcpcommand specifications.
Step 4: Re-run the Bulk Load Operation
- Execute your
BULK INSERTstatement orbcp incommand again, referencing the corrected format file. - Example T-SQL syntax:
BULK INSERT YourTable
FROM 'C:\BulkData\YourFile.csv'
WITH (
FORMATFILE = 'C:\BulkData\YourTable.fmt',
FORMAT = 'CSV'
);
- Monitor the output pane or terminal for confirmation that rows were successfully imported.
Alternative or Verification Steps
- Run
SELECT TOP 10 * FROM YourTable;after the load to confirm data populated correctly across all expected columns without truncation or misalignment. - If the error persists, bypass the custom format file entirely and use the simpler
FORMAT = 'CSV', FIELDTERMINATOR = ',', ROWTERMINATOR = '\r\n'inline options directly in theBULK INSERTstatement instead of referencing an external.fmtfile.