Why This Error Happens
Error 4894 occurs when the BCP (Bulk Copy Program) client sends a TDS (Tabular Data Stream) request to SQL Server 2025 without including the required COLMETADATA token, which describes the column structure of the incoming data. This typically happens when a custom application or outdated driver attempts to use the bulk copy API directly without properly initializing the metadata token stream. It can also occur if the data file’s format file is corrupted, mismatched, or was generated by an incompatible version of the bcp utility.
Step-by-Step Resolution Guide
Step 1: Verify the BCP Client and Driver Versions
- Confirm you are using the native
bcp.exeutility bundled with SQL Server 2025 tools, located typically atC:\Program Files\Microsoft SQL Server\160\Tools\Binn\bcp.exe. - Run
bcp -vin PowerShell or Command Prompt to check the version number. - Ensure the ODBC Driver 18 for SQL Server (or later) is installed, as older drivers (ODBC 11/13) may not correctly generate COLMETADATA tokens for newer TDS protocol versions.
Step 2: Regenerate the Format File
- Delete any existing
.fmtor.xmlformat files associated with the failing bulk operation. - Regenerate the format file using the
-fflag:
bcp YourDatabase.dbo.YourTable format nul -c -x -f C:\BCP\format.xml -S YourServer -T
- Re-run the import/export operation using the newly generated format file to rule out corruption as the cause.
Step 3: Check Custom Application Code (If Applicable)
- If the error originates from a custom C++/C# application using the Bulk Copy ODBC/OLE DB APIs directly (rather than
bcp.exe), review the code for missing calls toSQLBindColor the equivalent metadata binding function before callingSQLBulkOperations. - Ensure the application explicitly sends the COLMETADATA token prior to streaming row data; this is often a required manual step when bypassing the standard
bcp.exewrapper. - Update any legacy Native Client libraries (e.g.,
SQLNCLI) to the modern Microsoft OLE DB Driver for SQL Server, asSQLNCLIis deprecated and may not support TDS 8.0 metadata requirements in SQL Server 2025.
Step 4: Validate Network and TDS Protocol Compatibility
- Open SQL Server Configuration Manager and verify that TCP/IP is enabled under
SQL Server Network Configuration > Protocols. - Ensure no legacy proxy or network middleware (common in Windows Server 2025 environments with enhanced firewall rules) is intercepting and stripping TDS packets, which can truncate metadata tokens in transit.
- Restart the SQL Server service via
services.mscafter making configuration changes.
Alternative or Verification Steps
- Verify the Fix: Run a test bulk insert with a small sample CSV file using the
-c(character mode) flag to confirm the operation completes without Error 4894 before attempting large production loads. - Alternative Solution: If the error persists, bypass
bcp.exeentirely and use theOPENROWSET(BULK...)T-SQL command or theImport Flat Filewizard in SQL Server Management Studio (SSMS) 21, as these tools handle metadata token generation internally and are less prone to client-side driver mismatches.