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

Why This Error Happens

Error 4845 occurs when SQL Server’s BULK INSERT or OPENROWSET(BULK…) command parses a malformed data source provider string, typically due to a missing or misplaced delimiter, quote character, or bracket within the connection string syntax. This is commonly triggered by manually edited T-SQL scripts, incorrect escaping of special characters in file paths, or copy-pasted commands that lost formatting characters during transfer between editors. In SQL Server 2025, stricter parsing validation was introduced for bulk provider strings, meaning syntax that was previously tolerated may now explicitly fail at the character position indicated in the error.

Step-by-Step Resolution Guide

Step 1: Locate the Exact Character Position in the Query

  • Open the failing T-SQL script in SQL Server Management Studio (SSMS) or Azure Data Studio.
  • Use the character position number (%d) from the error message to count characters in your BULK INSERT or OPENROWSET string literal.
  • Pay close attention to single quotes ('), commas, and closing parentheses near that position.

Step 2: Correct the Provider String Syntax

  • Ensure the file path is wrapped correctly in single quotes, e.g., BULK 'C:\Data\import.csv'.
  • Verify that format file references use the correct syntax: WITH (FORMATFILE = 'C:\Data\format.xml').
  • If using UNC paths, confirm double backslashes are not accidentally duplicated or escaped incorrectly, e.g., \\Server\Share\file.csv.
  • Check for a missing expected character such as a closing single quote ' or parenthesis ), as indicated by the %lc placeholder in the error text.

Step 3: Validate File and Share Permissions

  • Confirm the SQL Server service account has Read permissions on the target file or network share.
  • Run the following to test connectivity to a UNC path from the SQL Server host:
  Test-Path "\\Server\Share\file.csv"
  • On Windows Server 2025, verify SMB signing or share-level permissions have not blocked access, which can sometimes surface as a provider string parsing issue if the path resolution fails upstream.

Step 4: Rebuild the Query Using a Clean Template

  • Discard the problematic script and rewrite the BULK INSERT statement from a known-good template.
  • Example template:
  BULK INSERT dbo.TargetTable
  FROM 'C:\Data\import.csv'
  WITH (
      FORMAT = 'CSV',
      FIRSTROW = 2,
      FIELDTERMINATOR = ',',
      ROWTERMINATOR = '\n'
  );
  • Re-enter file paths manually instead of pasting from external sources to avoid hidden Unicode or smart-quote characters.

Alternative or Verification Steps

  • Execute the corrected script in a new query window and confirm the bulk operation completes without raising Error 4845.
  • If the error persists, run the query through sp_executesql with the string stored in a variable first — this often reveals hidden non-printable characters causing the syntax break.