I get [Microsoft][ODBC Driver 11 for SQL Server]Unexpected EOF encountered in BCP data-file
on my production server but not on my test server.
Both servers have exactly the same set up, I am testing with same file from the same folder path on both servers. The database on the test server is a restored back-up taken from the production server.
bcp.exe version 2014.120.6169.19
SQL server version 12.0.6169.19
Windows Server 2012 R2
This is not a problem with the file encoding or the arguments of the BCP command, I have checked:
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110
and they are all the same.5f f0 d6 cf 46 b8 71 47 bc a0 fb ca 96 97 c8 e8
This has been working for years and stopped working within the last month.
UPDATE 2022-10-17
12.0.6439.10
but it made no differenceQuestion: Is there anything else I could check? Perhaps an environment variable which could be different on the production server?
This was caused by the code which prepares the BCP file: it selects the field -t
and row -r
delimiters to be the lowest char value not present in the data itself.
It caused BCP to fail for these two problems:
A) Badly formatted file: the same char was used for both field and row delimiter, which although already a problem in itself manifested in BCP as an uneven number of field delimiters, meaning the end of file was reached while reading a field.
Solution: make sure field -t
and row -r
delimiters are different
B) Unsupported delimiter chars: an incompatible character chosen for use as one of the delimiters, specifically in this case it was char(127)
. Similarly from further testing I found I also have to avoid using chars <=21
, in the range 127
to 160
, and char(173)
Solution: make sure you avoid delimiter characters in the ranges listed above
Both showed the same unhelpful error message [Microsoft][ODBC Driver 11 for SQL Server]Unexpected EOF encountered in BCP data-file
The reason this did not also happen on the test server: For optimisation the each server remembers and re-uses delimiters detected during previous imports, at some point the production server had been trained on to the problematic delimiters by an older data import which the test server had never seen. So the test server still had valid delimiters cached but the production server had bad ones.