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

Troubleshooting Guide: Error 4137 – “A format file cannot be specified together with SINGLE_BLOB”

Why This Error Happens

This error occurs when a BULK INSERT or OPENROWSET(BULK...) statement incorrectly combines the SINGLE_BLOB option with a FORMATFILE parameter in the same query. The SINGLE_BLOB option tells SQL Server to import the entire file as a single, unparsed binary value, which fundamentally conflicts with the purpose of a format file, since format files are used to define column-level parsing and mapping rules for structured data. Because these two options have mutually exclusive goals—one treats the data as unstructured and the other requires structured mapping—SQL Server 2025 rejects the syntax outright.

Step-by-Step Resolution Guide

Step 1: Identify the Conflicting Query Syntax

  • Open SQL Server Management Studio (SSMS) or Azure Data Studio and locate the exact BULK INSERT or OPENROWSET statement throwing Error 4137.
  • Check the WITH clause of your query for the simultaneous presence of SINGLE_BLOB and FORMATFILE = 'path\to\file.xml'.
  • Example of broken syntax: WITH (SINGLE_BLOB, FORMATFILE = 'C:\Data\format.xml').

Step 2: Determine Your Intended Import Type

  • Decide whether you actually need to import the file as unstructured binary data (images, JSON blobs, or XML files) or as structured tabular data (CSV, TXT).
  • If you need structured parsing (columns and rows), you must remove SINGLE_BLOB entirely.
  • If you need to treat the file as a single object (e.g., for use with OPENROWSET to load JSON into a variable), you must remove the FORMATFILE reference entirely.

Step 3: Modify the Query for Structured Data

  • Remove the SINGLE_BLOB keyword from the WITH clause if you require column mapping.
  • Ensure the format file path is accessible to the SQL Server service account, for example: C:\SQLData\Import\format.xml.
  • Update the syntax to: BULK INSERT dbo.YourTable FROM 'C:\Data\file.csv' WITH (FORMATFILE = 'C:\Data\format.xml', FIRSTROW = 2);

Step 4: Modify the Query for Binary/Blob Data

  • If unstructured data is required, remove the FORMATFILE parameter from the statement.
  • Update the syntax to use only the blob option: SELECT * FROM OPENROWSET(BULK 'C:\Data\image.jpg', SINGLE_BLOB) AS ImageData;
  • Verify there are no residual commas or syntax artifacts left from the removed parameter that could cause a secondary syntax error.

Alternative or Verification Steps

  • Execute the corrected query in a test environment first; a successful execution without Error 4137 confirms the syntax conflict has been resolved.
  • If you need both binary storage and metadata, consider importing the file via SINGLE_BLOB into a staging table with a VARBINARY(MAX) column first, and then use a separate, secondary script to parse and insert structured data into the final destination table.